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

Added: Signup view with respective url, Signup and success page. #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 Django_To_Do/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Main',
]

MIDDLEWARE = [
Expand Down
4 changes: 3 additions & 1 deletion Main/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.urls import path
from .views import index_view
from .views import index_view, signup_view, success_view

urlpatterns = [
path('', index_view, name='index'),
path('success/', success_view, name='success-signup'),
path('signup/', signup_view, name='signup'),
]
26 changes: 23 additions & 3 deletions Main/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth import login, authenticate
from django.contrib.auth.forms import UserCreationForm

# Create your views here.

def index_view(request):
if request.method == 'GET':
return render(request, 'Index.html')
return HttpResponse(405)
return render(request, 'Main/index.html')
return HttpResponse(405)

def signup_view(request):
if request.method == 'POST':
form = UserCreationForm(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("success-signup")
else:
form = UserCreationForm()
return render(request, 'Main/signup.html', {'form':form})

def success_view(request):
if request.method == 'GET':
return render(request, 'Main/success-signup.html')
return HttpResponse(405)
6 changes: 6 additions & 0 deletions templates/Main/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>Welcome to Django To-Do!</h2>
<ul>
<li>
<a href="/signup/">Sign-up</a>
</li>
</ul>
6 changes: 6 additions & 0 deletions templates/Main/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Sign up</button>
</form>
3 changes: 3 additions & 0 deletions templates/Main/success-signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>
Successfully signed up.
</h1>