These are chat archives for django/django

27th
Feb 2018
:]
@elcolie
Feb 27 2018 04:24
@dprateek11 Put break poink import pdb; pdb.set_trace() and try check your user is anonymouse or not
@yadneshk Yes, I do. I do recommend redis
@thesanjeevsharma Whati is the error code?
:]
@elcolie
Feb 27 2018 04:33
Hi
django-money/django-money#379
I wants to know how do you deal with calculated money instance from dj-money
Sanjeev Sharma
@thesanjeevsharma
Feb 27 2018 06:13
@elcolie It says url doesn't match on Pythonanywhere but on local host it works.
ysaito8015
@ysaito8015
Feb 27 2018 07:18
Hi
Prateek Dabas
@dprateek11
Feb 27 2018 07:50
hi
def get_user_id(request):
print request.user.id
how can i call this function in django admin
Roel
@roelzkie15
Feb 27 2018 07:52
@dprateek11 what do you mean by django admin? by console command? Forms?
Prateek Dabas
@dprateek11
Feb 27 2018 07:54
i mean if admin.site.register(Vacancy, VacancyAdmin)
if this line of code runs then my function should be called automaticallly
and it should print user id in the terminal
:]
@elcolie
Feb 27 2018 09:16
@thesanjeevsharma Did you hardcode the url?
I am blind here without traceback. Could you post it in gist in the Github or stackoverflow please?

Then use this

import logging
logger = logging.getLogger('django')

Suppose you can write log file on your given VM try logging the issue
Then put logger.info(...)

Valentino Gagliardi
@valentinogagliardi
Feb 27 2018 13:03
hello there! I'm writing a tutorial on Django / Django REST + React
robotiguy
@robotiguy
Feb 27 2018 13:03

0
down vote
favorite
I am fairly new to Django and I have set up a sign up form with some additional fields.

In my forms.py file I have the following code:

class SignUpForm(UserCreationForm):
    first_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
    last_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
    email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )

In my views.py I have the following code:

def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})

Then in my signup.html view I am rendering the following:

<form method="post">
    {% csrf_token %}
    {% for field in form %}
      <p>
        {{ field.label_tag }}<br>
        {{ field }}
        {% for error in field.errors %}
          <p style="color: red">{{ error }}</p>
        {% endfor %}
      </p>
    {% endfor %}
    <button class="btn-contact" type="submit">Let's Go!</button>
  </form>

Essentially what I want to do is add placeholder text in each field but this is not appearing the way I have set it up.

To do this I need more control over the forms fields but I don't know how to do that because of the way I am rendering fields in a loop.

How would I go about doing this?

Valentino Gagliardi
@valentinogagliardi
Feb 27 2018 13:04
does anybody would like to see a preview?
Nnamdi
@nnamdiib
Feb 27 2018 16:11
@valentinogagliardi for more control over your form friends, you can render each field manually like this: {{ form.field_name }}
email =
Ahh sorry my phone keeps messing up. I can't seem to type in formatted code for some reason.
Nnamdi
@nnamdiib
Feb 27 2018 16:16
Will come back to this once I get to my computer.
Sanket
@sdoshi579
Feb 27 2018 18:16
Any best tutorials to learn Django please??
siddiqui776
@siddiqui776
Feb 27 2018 19:05
i had made forms.py and all editing i have done in base.html.but after refreshing it is not showing form.
what should i do