why is my input fields not showing in the website? - django

I have created a login and registration page using the same code. The registration page shows username input fields and other fields but the login page only shows the button. Can anyone help me in this
Code:
Login Page:
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="{% url 'login' %}">Sign In</a>
</small>
</div>
</div>
Registration Page:
<div class="site-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Log In </legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Login</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Need An Account? <a class="ml-2" href="{% url 'register' %}">Sign Up Now</a>
</small>
</div>
</div>
Registration page
Login page
This is the views of the project
Views.py
from django.shortcuts import render, redirect
from django.contrib import messages
from .forms import UserRegisterForm
from .models import Post
from django.contrib.auth.decorators import login_required
def home(request):
context = {
'posts': Post.objects.all()
}
return render(request, 'blog/home.html', context)
def about(request):
return render(request, 'blog/about.html', {'title': 'About'})
def gallery(request):
return render(request, 'blog/gallery.html', {'title': 'Gallery'})
def foodopedia(request):
return render(request, 'blog/foodopedia.html', {'title': 'Foodopedia'})
def register(request):
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
return redirect('blog-home')
else:
form = UserRegisterForm()
return render(request, 'blog/register.html', {'form': form})
def login(request):
return render(request, 'blog/login.html', {'title': 'Login'})
#login_required
def profile(request):
return render(request, 'blog/profile.html', {'title': 'Profile'})
def upload(request):
context = {}
if request.method == 'POST':
uploaded_file = request.FILES['document']
fs = FileSystemStorage()
name = fs.save(uploaded_file.name, uploaded_file)
context['url'] = fs.url(name)
context['filename'] = name
pred, probability = process_image(name)
context['prediction'] = pred
context['probability'] = probability
return render(request, 'blog/foodopedia.html', context)
This is the urls.py of the project
from django.contrib import admin
from django.urls import path, include
from blog import views as blog_views
from django.contrib.auth import views as auth_views
from blog import views as blog_views
urlpatterns = [
path('admin/', admin.site.urls),
path('register/', blog_views.register, name='register'),
path('profile/', blog_views.profile, name='profile'),
path('', include('blog.urls')),
path('login/', auth_views.LoginView.as_view(template_name='blog/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='blog/logout.html'), name='logout'),
]
This is the form.py file:
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']

You forgot to create a new form in forms.py, then also dont forget to enhance your login view.

You could try using this, adapted from the example in this tutorial:
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.forms import AuthenticationForm
def login(request):
if request.user.is_authenticated:
return redirect('/')
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('/')
else:
form = AuthenticationForm(request.POST)
return render(request, 'blog/login.html', {'form': form, 'title': 'Login'})
else:
form = AuthenticationForm()
return render(request, 'blog/login.html', {'form': form, 'title': 'Login'})
To use that you would have to change the login line in your urls.py to this:
path('login/', blog_views.login, name='login'),

Related

request.user.is_authenticated does not work after changing urls

So my code looked like this at first:
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Information
from django.db.models import Q
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from .forms import MyForm
# rooms = [
# {'id': 1, 'name': 'Lets learn python!'},
# {'id': 2, 'name': 'Design with me'},
# {'id': 3, 'name': 'Frontend developers'},
# ]
def home(request):
q = request.GET.get('q') if request.GET.get('q') !=None else ''
information_search = Information.objects.filter(
Q(host__icontains=q) |
Q(hostname__icontains=q) |
Q(port__icontains=q) |
Q(platform__icontains=q) |
Q(username__icontains=q) |
Q(password__icontains=q) |
Q(groups__icontains=q)
)
sort_info = []
informations = Information.objects.all()
for i in informations:
if i.groups not in sort_info:
device_group = i.groups
sort_info.append(device_group)
information_count=information_search.count()
context = {'informations':informations, 'information_search':information_search, 'information_count':information_count, 'sort_info':sort_info}
return render(request, 'polls/home.html', context)
def view_data(request, pk):
information = Information.objects.get(id=pk)
context = {'information':information}
return render(request, 'polls/view_data.html', context)
def loginPage(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
try:
user = User.objects.get(username=username)
except:
messages.error(request, 'User does not exist')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
messages.error(request, "Username or password does not exist")
context = {}
return render(request, 'polls/login_register.html', context)
def logoutUser(request):
logout(request)
return redirect('home')
def edit_data(request, pk):
information = Information.objects.get(id=pk)
form = MyForm(instance=information)
if request.method == 'POST':
form = MyForm(request.POST, instance=information)
if form.is_valid():
form.save()
return redirect('home')
context = {'form': form}
return render(request, 'polls/room_form.html', context)
def delete_data(request, pk):
information = Information.objects.get(id=pk)
if request.method == 'POST':
information.delete()
return redirect('home')
return render(request, 'polls/delete.html', {'obj': information})
def my_form(request):
if request.method == "POST":
form = MyForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
form = MyForm()
return render(request, 'polls/room_form.html', {'form': form})
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),
path('', views.home, name='home'),
path('view_data/<str:pk>/', views.view_data, name = "view_data"),
path('edit_data/<str:pk>/', views.edit_data, name = "edit_data"),
path('host/', views.my_form, name='my_form'),
path('delete/<str:pk>/', views.delete_data, name='delete_data')
]
login_register.html
{% extends 'main.html' %}
{% block content %}
<div>
<form method="POST" action="">
{% csrf_token %}
<label>Username:</label>
<input type="text" name="username" placeholder="Enter Username" />
<label>Password:</label>
<input type="password" name="password" placeholder="Enter Password">
<input type="submit" value="login">
</form>
</div>
{% endblock content %}
I wanted to change the authentication system so that the home view is only returned if the user is logged in. I was able to show home view after the user logs in by making small changes to urls.py and login_register.html as follows:
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Information
from django.db.models import Q
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from .forms import MyForm
# rooms = [
# {'id': 1, 'name': 'Lets learn python!'},
# {'id': 2, 'name': 'Design with me'},
# {'id': 3, 'name': 'Frontend developers'},
# ]
def home(request):
q = request.GET.get('q') if request.GET.get('q') !=None else ''
information_search = Information.objects.filter(
Q(host__icontains=q) |
Q(hostname__icontains=q) |
Q(port__icontains=q) |
Q(platform__icontains=q) |
Q(username__icontains=q) |
Q(password__icontains=q) |
Q(groups__icontains=q)
)
sort_info = []
informations = Information.objects.all()
for i in informations:
if i.groups not in sort_info:
device_group = i.groups
sort_info.append(device_group)
information_count=information_search.count()
context = {'informations':informations, 'information_search':information_search, 'information_count':information_count, 'sort_info':sort_info}
return render(request, 'polls/home.html', context)
def view_data(request, pk):
information = Information.objects.get(id=pk)
context = {'information':information}
return render(request, 'polls/view_data.html', context)
def loginPage(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
try:
user = User.objects.get(username=username)
except:
messages.error(request, 'User does not exist')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
messages.error(request, "Username or password does not exist")
context = {}
return render(request, 'polls/login_register.html', context)
def logoutUser(request):
logout(request)
return redirect('home')
def edit_data(request, pk):
information = Information.objects.get(id=pk)
form = MyForm(instance=information)
if request.method == 'POST':
form = MyForm(request.POST, instance=information)
if form.is_valid():
form.save()
return redirect('home')
context = {'form': form}
return render(request, 'polls/room_form.html', context)
def delete_data(request, pk):
information = Information.objects.get(id=pk)
if request.method == 'POST':
information.delete()
return redirect('home')
return render(request, 'polls/delete.html', {'obj': information})
def my_form(request):
if request.method == "POST":
form = MyForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
form = MyForm()
return render(request, 'polls/room_form.html', {'form': form})
login_register.html
{% extends 'main.html' %}
{% block content %}
<div>
<form method="POST" action="home/">
{% csrf_token %}
<label>Username:</label>
<input type="text" name="username" placeholder="Enter Username" />
<label>Password:</label>
<input type="password" name="password" placeholder="Enter Password">
<input type="submit" value="login">
</form>
</div>
{% endblock content %}
However the bar at navbar.html which shows logout option if the user is logged in stops working..
navbar.html
<a href="/polls">
<h1>LOGO</h1>
</a>
<form method="GET" action="{% url 'home' %}">
<input type="text" name="q" placeholder="Search Devices...">
</form>
{% if request.user.is_authenticated %}
Logout
{% else %}
Login
{% endif %}
<hr>
navbar is included in main.html as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>StudyBud</title>
</head>
<body>
{% include 'navbar.html' %}
{% block content %}
{% endblock %}
</body>
</html>
and main.html is extended by other templates. Here main.html and navbar.html are stored in the templates folder of the root directory while other templates are in the 'polls' app folder.
If it helps here are my other files.
models.py
from django.db import models
from django.contrib.auth.models import User
class Information(models.Model):
host = models.CharField(max_length=200, null=True, blank=False)
hostname = models.CharField(max_length=200, null=True, blank=False)
port = models.IntegerField()
platform = models.CharField(max_length=200, null=True, blank=False)
username = models.CharField(max_length=200, null=True, blank=False)
password = models.CharField(max_length=200, null=True, blank=False)
groups = models.CharField(max_length=200, null=True, blank=False)
def __str__(self):
return self.host
Here is home.html which extends main.html and is supposed to show the logout bar.
{% extends 'main.html' %}
{% block content %}
<h2>Inventory Management</h2>
<style>
.home-container{
display: grid;
grid-template-columns: 1fr 3fr;
}
</style>
<div class="home-container">
<div>
<h3>Browse Groups</h3>
<hr>
{% for i in sort_info %}
<div>
{{i}}
<br><br>
</div>
{% endfor %}
</div>
<div>
<h5>{{information_count}} devices registered</h5>
<hr>
Add Device
<hr>
{% for information in information_search %}
<span>#{{information.host}}</span>
<h3> view </h3>
Edit
Delete
<hr>
{% endfor %}
</div>
</div>
{% endblock content %}
</div>
Any insight please? I am a beginner and I was trying to make changes and implement my own features in the code i followed through a tutorial.

Signup Form Fields are not rendering Django

Here is my code
In Urls.py
from django.contrib.auth import authenticate, login, logout
from .forms import CustomUserCreationForm
def registeruser(request):
form = CustomUserCreationForm()
if request.method == "POST":
form = CustomUserCreationForm(request, POST)
if form.is_valid():
user = form.save(commit=False)
user.save()
user = authenticate(request, username=user.username, password=request.POST['password'])
if user is not None:
login(request, user)
return redirect('home')
context = {'form' : form}
return render(request, 'signup.html', context)
urlpatterns = [
path('signup/', registeruser, name='signup'),
]
In forms.py
from django.forms import ModelForm
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = User
fields = ['username', 'password1', 'password2']
def __init__(self, *args, **kwargs):
super(CustomUserCreationForm, self).__init__(self, *args, **kwargs)
self.fields['username'].widget.attrs.update({'class' : 'form-control', 'placeholder' : 'Enter Username'})
self.fields['password1'].widget.attrs.update({'class' : 'form-control', 'placeholder' : 'Enter Password'})
self.fields['password2'].widget.attrs.update({'class' : 'form-control', 'placeholder' : 'Re-Enter Password'})
In Signup.html
<form class="text-left clearfix" method="POST">
{% csrf_token %}
{% for field in forms %}
<div class="form-group">
{{field}}
</div>
{% endfor %}
<div class="text-center">
<button type="submit" class="btn btn-main text-center">Sign UP</button>
</div>
</form>
Result is
Signup page image
I tried alot of settings but got no input field on signup page. It just render nothing.
Please help me what am i doing wrong?
Instead of using a for loop, try just using form.
#view.py
return render(request, 'signup.html', {'form': form})
#signup
<form class="text-left clearfix" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="btn btn-main text-center" value="Sign UP">
</form>

Profile is not getting created for the new user after extension of the user model

Before extending the user module, I was easily able to register new users and the page would get redirected to the login page. Now on registering new users, the profile is not getting created and the page is also not getting redirected. The new user does get created though and sometimes the error is object does not exist, user profile does not exist, and sometimes the error is forbidden, csrf verification failed. I dont know where I'm going wrong. existing users are able to login and update profiles but new users I'm having a problem with.
Models.py is:
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User,null= True ,on_delete= models.CASCADE)
profile_pic = models.ImageField(null = True, blank= True)
first = models.CharField(max_length=500, null=True)
last = models.CharField(max_length=500, null=True)
email = models.CharField(max_length=500, null=True)
mobile_number = models.IntegerField(null=True)
location = models.CharField(max_length= 500, null= True)
postal = models.IntegerField(null=True)
def __str__(self):
return self.first
My forms.py is:
from django.forms import ModelForm, fields
from django.contrib.auth.forms import UserCreationForm
from django import forms
from django.contrib.auth.models import User
from .models import *
class CreateUserForm(UserCreationForm):
email = forms.EmailField()
password2 = None
class Meta:
model = User
fields = ['username','first_name', 'last_name','email', 'password1']
class ProfileForm(ModelForm):
class Meta:
model = Profile
fields = '__all__'
exclude = ['user']
widgets = {
'profile_pic': forms.FileInput()
}
views.py is (I removed the login and logout view cause that was working fine):
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from .forms import CreateUserForm, ProfileForm
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth.decorators import login_required
from .models import *
def RegisterPage(request):
if request.user.is_authenticated:
return redirect('Profile')
else:
if request.method == 'POST':
form = CreateUserForm(request.POST)
if form.is_valid():
user = form.save()
name = form.cleaned_data.get('first_name')
messages.success(request, 'Account created for ' + name)
Profile.object.create(
user = user,
)
Profile.save()
return HttpResponseRedirect('/Login/')
else:
form = CreateUserForm()
context = {'form':form}
return render(request, 'register.html', context)
#login_required(login_url='Login')
def Profile(request):
profile = request.user.profile
form = ProfileForm(instance=profile)
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES, instance=profile)
if form.is_valid():
form.save()
context = {'form': form}
return render(request, 'profile.html', context)
my register template:
<form class="" action="" method="post">
{% csrf_token %}
<p class="reg-field-title"><strong>Username*</strong></p>
<div class="forms">{{form.username}}</div>
<p class="reg-field-title"><strong>First Name*</strong></p>
<div class="forms">{{form.first_name}}</div>
<p class="reg-field-title"><strong>Last Name*</strong></p>
<div class="forms">{{form.last_name}}</div>
<p class="reg-field-title"><strong>Email-ID*</strong></p>
<div class="forms">{{form.email}}</div>
<p class="reg-field-title"><strong>Password*</strong></p>
<div class="forms">{{form.password1}}</div>
<button type="submit" class="btn btn-dark btn-lg col-lg-10 reg-btn">Register</button>
</form>
My login template:
<p class="login-reg">New to MedsPlain? <a class="log-reg-link" href="/Registration/">Register </a>here</p>
<hr> {% if next %}
<form class="" action='/Login/Profile/' method="post"> {% csrf_token %} {%else%}
<form class="" action="/Login/" method="post">
{% endif %} {% csrf_token %}
<p class="login-field-title"><strong>Username*</strong></p>
<input type="text" name="username" class="form-control col-lg-10 log-inp-field" placeholder="Enter Username" required>
<p class="login-field-title"><strong>Password*</strong></p>
<input type="password" name="password" class="form-control col-lg-10 log-inp-field" placeholder="Enter Password" required> {% for message in messages %}
<p id="messages">{{message}}</p>
{% endfor %}
<button type="submit" class="btn btn-dark btn-lg col-lg-10 log-btn">Log In</button>
</form>
I've tried everything as of now, but i don't understand the mistake. Can someone please guide me through cause at this moment i'm frustrated, on the verge of crying and don't understand what to do.
There are basically two problems here:
there is a view Profile, and thus this will override the reference to the Profile model; and
you do not create a model record with Model.object.create(), but with Model.objects.create().
I would advise that you rename your views in snake_case, and remove the wildcard import, this is often not a good idea:
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from .forms import CreateUserForm, ProfileForm
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth.decorators import login_required
from .models import Profile
def register_page(request):
if request.user.is_authenticated:
return redirect('Profile')
else:
if request.method == 'POST':
form = CreateUserForm(request.POST)
if form.is_valid():
user = form.save()
Profile.objects.create(
user = user,
)
messages.success(request, 'Account created for {user.first_name}')
return HttpResponseRedirect('/Login/')
else:
form = CreateUserForm()
context = {'form': form }
return render(request, 'register.html', context)
#login_required(login_url='Login')
def profile(request):
profile = request.user.profile
form = ProfileForm(instance=profile)
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES, instance=profile)
if form.is_valid():
form.save()
context = {'form': form}
return render(request, 'profile.html', context)
You will also need to update the urls.py to work with the renamed views.

Logout function in Django not working as Expected

I have not used any middleware, when i click on logout button on my Home Page template, the logout function execute without any error.but when i go back to main page without jumping to login page.. i see myself as logged in user
here is my authentiCation/views.py
from django.shortcuts import render
from django.http import request,HttpResponseRedirect
# for user creation & login form
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login
# for user related Queries
from django.contrib.auth.models import User
# imports for test purpose
from django.http import HttpResponse
# Create your views here.
# register page
def register_Page(request):
if request.method == 'POST':
form= UserCreationForm(request.POST)
if form.is_valid():
form.save()
username= request.POST['username']
password= request.POST['password1']
user= authenticate(request,username=username,password=password)
login(request,user)
return HttpResponseRedirect('/')
else:
return HttpResponse('Either the user name is not available or you may have filled the form incorrectly')
else:
form = UserCreationForm()
context= {'form':form}
return render(request,'authentication/register_Page.html',context)
# login page
def login_page(request):
if request.method == 'POST':
username= request.POST['username']
password= request.POST['password']
# returns user if credentials are valid
user= authenticate(request, username=username, password= password)
# check if user var contains the user
if user is not None:
login(request, user)
return HttpResponseRedirect('/')
else:
return HttpResponse('Invalid credentials')
return render(request,'authentication/login.html')
# logout Page
def log_out(request):
logout(request)
return HttpResponseRedirect('logout_page')
authentiCation/urls.py
from django.urls import path
from authentiCation import views
urlpatterns = [
path('register/',views.register_Page),
path('login/',views.login_page,name='login_page'),
path('logout/',views.log_out),
]
Main App Files
urls
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('App_wfi_Community.urls')),
path('Ask/',include('askQuestion.urls')),
path('auth/',include('authentiCation.urls')),
]
Home.html
{% extends "basic.html" %}
{% load humanize %}
{% block title %}WFI-Community{% endblock title %}
{% block body %}
<!-- search button -->
<h5>Welcome {{username}},<h5> <!-- I see my username here -->
<form action="/search" method="get">
<div class="container py-3 row">
<div class="col-md-8 offset-2">
<div class="input-group">
<input name="searchfieldText" type="text" class="form-control" placeholder="Search">
<button class="btn btn-danger" type="submit">Search</button>
<span>Logout</span>
</div>
</div>
</div>
</form>
<!-- and some more HTML stuff which is irrelavent here -->
Give a name to this eg
path('logout/',views.log_out, name="logout" ) and change it in the home.html.
eg "{% url 'logout' %}">Logout

NoReverseMatch (Reverse for ' user_login' not found)

I have a django project called log and an application called basic_app. I created a register form but when I want to create a user_login, I get this error:
NoReverseMatch at /basic_app/user_login/
Reverse for ' user_login' not found. ' user_login' is not a valid view function or pattern name.
views.py:
from django.shortcuts import render
from basic_app.forms import UserForm, UserProfileInfoForm
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
return render(request, 'basic_app/index.html')
#login_required
def special(request):
return HttpResponse('You are loged in!')
#login_required
def user_logout(request):
logout(request)
return HttpResponseRedirect(reverse('index'))
def register(request):
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileInfoForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES[
'profile_pic'
]
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm()
return render(request, 'basic_app/registration.html',
{'user_form':user_form,
'profile_form':profile_form,
'registered':registered})
def user_login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username = username, password = password)
if user:
if user.is_active:
login(request, user)
return HttpResponseRedirect(reverse('index'))
else:
return HttpResponse('Account Not Active.')
else:
print('Someone tried to login and failed!')
print('username:{} and password:{}'.format(username, password))
return HttpResponse('invalid login details supplied!')
else:
return render(request, 'basic_app/login.html',{})
basic_app/urls.py:
from django.conf.urls import url
from basic_app import views
#TEMPLATE URLS
app_name = 'basic_app'
urlpatterns = [
url(r'^register/$', views.register, name='register'),
url(r'^user_login/$', views.user_login, name='user_login'),
log/urls.py:
from django.conf.urls import url, include
from django.contrib import admin
from basic_app import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^admin/', admin.site.urls),
url(r'^basic_app/', include('basic_app.urls')),
url(r'^logout/$', views.user_logout, name='logout'),
url(r'special/', views.special, name='special')
login.html:
{% extends 'basic_app/basic.html' %}
{% block body_block %}
<div class="jumbotron">
<h1>Please Login: </h1>
<form action="{% url 'basic_app: user_login' %}" method="post">
{% csrf_token %}
<label for="username">Username:</label>
<input type="text" name="username" placeholder="Enter Username">
<label for="passwrod">Password:</label>
<input type="password" name="password">
<input type="submit" name="" value="Login">
</form>
</div>
{% endblock %}