Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Basic registration #149

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions catalog/templates/base_generic.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</li>
{% else %}
<li><a href="{% url 'login'%}?next={{request.path}}">Login</a></li>
<li><a href="{% url 'register' %}">Register</a></li>
{% endif %}
</ul>

Expand Down
4 changes: 2 additions & 2 deletions locallibrary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from django.conf import settings
from django.conf.urls.static import static


urlpatterns+= static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


Expand All @@ -45,9 +44,10 @@
path('', RedirectView.as_view(url='/catalog/', permanent=True)),
]


from . import views

# Add Django site authentication urls (for login, logout, password management)
urlpatterns += [
path('accounts/', include('django.contrib.auth.urls')),
path('register/', views.register_user, name='register'),
]
18 changes: 18 additions & 0 deletions locallibrary/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login


def register_user(request):
if request.method != 'POST':
form = UserCreationForm()
else:
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return redirect('index')

context = {'form': form}
return render(request, 'registration/register_user.html', context)
11 changes: 11 additions & 0 deletions templates/registration/register_user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base_generic.html" %}

{% block content %}

<form action="" method="post">
{% csrf_token %} {{form.as_p}}

<input type="submit" value="Create account" name="Create account" />
</form>

{% endblock %}
Loading