Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.conf.urls import url
- from django.views.generic import ListView, TemplateView
- from .models import Dreamreal
- from . import views
- urlpatterns = [
- url(r'^connection/login/$', views.login),
- url(r'^connection/$', TemplateView.as_view(template_name =
- 'login.html')),
- url(r'^login/$', views.login, name = 'login')
- ]
- from .forms import LoginForm
- from . import models
- def login(request):
- username = "not logged in"
- if request.POST:
- # GET THE POSTED FORM
- MyLoginForm = LoginForm(request.POST)
- if MyLoginForm.is_valid():
- username = MyLoginForm.cleaned_data['username']
- else:
- MyLoginForm = LoginForm()
- return render(request, 'loggedin.html', {'username' : username})
- from django import forms
- from .models import Dreamreal
- class LoginForm(forms.Form):
- username = forms.CharField(max_length = 100)
- password = forms.CharField(widget = forms.PasswordInput())
- # METHOD TO VERIFY IF USER IS IN DB
- def clean_message(self):
- username = self.cleaned_data.get("username")
- dbuser = Dreamreal.objects.filter(name = 'username')
- if not dbuser:
- raise forms.ValidationError("User does not exist in our db!")
- return username
- from django.db import models
- class Dreamreal(models.Model):
- website = models.CharField(max_length = 50)
- mail = models.CharField(max_length = 50)
- name = models.CharField(max_length = 50)
- phonenumber = models.IntegerField()
- class Meta:
- db_table = 'dreamreal'
- <html>
- <head>
- <title>LOG IN</title>
- </head>
- <body>
- <form name="form" action="/connection/login/" method="POST">
- {% csrf_token %}
- <div style="max-width: 470px;">
- <center><input type="text" name="username"
- placeholder="username" style="margin-left: 20%;" required>
- </center>
- </div>
- <br>
- <div style="max-width: 470px;">
- <center><input type="password" name="password"
- placeholder="password" style="margin-left: 20%;"></center>
- </div>
- <br>
- <div style="max-width: 470px;">
- <center><button style = "border:0px; background-color:#4285F4;
- margin-top:8%; height:35px; width:80%;margin-left:19%;" type =
- "submit" value = "Login" >
- <strong>Login</strong>
- </button></center>
- </div>
- </form>
- </body>
- </html>
- {% extends 'base.html' %}
- <html>
- <head>
- <title>{% block title%}{{ username }}{% endblock %}</title>
- </head>
- <body>
- {% block content %}
- You are : <strong>{{ username }}</strong>
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement