Skip to content
Snippets Groups Projects
Commit 84778b24 authored by Saif Ali's avatar Saif Ali
Browse files

Saif Ali:

 login and signup python codes along with html and css codes
parent 6935768b
No related branches found
No related tags found
No related merge requests found
Showing
with 92 additions and 0 deletions
File added
File added
File added
File added
File added
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AccountsConfig(AppConfig):
name = 'accounts'
File added
from django.db import models
# Create your models here.
{% extends 'base_layout.html' %}
{% block content %}
<h1>Log in</h1>
<form class="site-form" action="{% url 'accounts:login' %}" method="post">
{% csrf_token %}
{{ form }}
{% if request.GET.next %}
<input type="hidden" name="next" value="{{ request.GET.next }}" />
{% endif %}
<input type="submit" value="Login" />
</form>
<p>Not got an account? <a href="{% url 'accounts:signup' %}">Sign Up</a></p>
{% endblock %}
#5 in the accounts url i want to use login url
{% extends 'base_layout.html' %}
{% block content %}
<h1>Signup</h1>
<form class="site-form" action="/accounts/signup/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Signup">
</form>
{% endblock %}
#6 is the security csrf_token which server gets and knows that data is comming from your application
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from . import views
app_name = 'accounts'
urlpatterns = [
url(r'^signup/$', views.signup_view, name="signup"),
url(r'^login/$', views.login_view, name="login"),
url(r'^logout/$', views.logout_view, name="logout"),
]
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth import login, logout
def signup_view(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
# log the user in
login(request, user)
return redirect('articles:list')
else:
form = UserCreationForm()
return render(request, 'accounts/signup.html', { 'form': form })
def login_view(request):
if request.method == 'POST':
form = AuthenticationForm(data=request.POST)
if form.is_valid():
# log the user in
user = form.get_user()
login(request, user)
return redirect('articles:list')
else:
form = AuthenticationForm()
return render(request, 'accounts/login.html', { 'form': form })
def logout_view(request):
if request.method == 'POST':
logout(request)
return redirect('articles:list')
#user is varialbe in 22 which is going to retrieve the info of the user trying to login
#on 10 and 21 we are not logging in the users but redirecting them
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment