These are chat archives for django/django

Feb 2018
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?
Feb 27 2018 04:33
I wants to know how do you deal with calculated money instance from dj-money
Sanjeev Sharma
Feb 27 2018 06:13
@elcolie It says url doesn't match on Pythonanywhere but on local host it works.
Feb 27 2018 07:18
Prateek Dabas
Feb 27 2018 07:50
def get_user_id(request):
how can i call this function in django admin
Feb 27 2018 07:52
@dprateek11 what do you mean by django admin? by console command? Forms?
Prateek Dabas
Feb 27 2018 07:54
i mean if, VacancyAdmin)
if this line of code runs then my function should be called automaticallly
and it should print user id in the terminal
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

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

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

In my 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 I have the following code:

def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            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')
        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 %}
        {{ field.label_tag }}<br>
        {{ field }}
        {% for error in field.errors %}
          <p style="color: red">{{ error }}</p>
        {% endfor %}
    {% endfor %}
    <button class="btn-contact" type="submit">Let's Go!</button>

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
Feb 27 2018 13:04
does anybody would like to see a preview?
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.
Feb 27 2018 16:16
Will come back to this once I get to my computer.
Feb 27 2018 18:16
Any best tutorials to learn Django please??
Feb 27 2018 19:05
i had made and all editing i have done in base.html.but after refreshing it is not showing form.
what should i do