E
E
ellz2019-03-21 22:14:28
Django
ellz, 2019-03-21 22:14:28

What is the best way to register in djnago?

The first time you run the migrate command, django creates several tables in the database, including auth_user. This is where user data is stored. But what if I need more data to be there? For example, if I need a phone number: is it better to create a new field in this table or create a new table with phone numbers associated with auth_user? Or maybe it's better to create your own table with users and register them using procedures in the database, and not something like this:

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

One more question:
{% if user.is_authenticated %}
<form id="logoutForm" action="/logout" method="post" class="navbar-right">
    {% csrf_token %}
    <ul class="nav navbar-nav navbar-right">
        <li><span class="navbar-brand">Hello {{ user.username }}!</span></li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
    </ul>
</form>

{% else %}

<ul class="nav navbar-nav navbar-right">
    <li><a href="{% url 'login' %}">Log in</a></li>
</ul>

{% endif %}

{% if user.is_authenticated %}#откуда django вообще берет user, если я этого не в одной функции не передаю?
works with standard auth_user table? Then, if you make everything custom, will it need to be passed through context as a variable? How then to make sure that after reloading the page or after redirecting the user does not crash? And do they often do authentication in a non-standard way (LoginView)?
PS
посмотрел много уроков и на русском и на английском - ничего чтобы мне помогло бы не нашел

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question