Guest User

Untitled

a guest
Mar 2nd, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. from django.contrib.auth import authenticate, login
  2. from django.http import HttpResponse
  3. from django.shortcuts import render, redirect
  4.  
  5. from .forms import ContactForm, LoginForm, RegisterForm
  6.  
  7. def home_page(request):
  8. context = {
  9. "title":"Hello World!",
  10. "content":" Welcome to the homepage.",
  11.  
  12. }
  13. if request.user.is_authenticated():
  14. context["premium_content"] = "YEAHHHHHH"
  15. return render(request, "home_page.html", context)
  16.  
  17.  
  18.  
  19.  
  20.  
  21. def about_page(request):
  22. context = {
  23. "title":"About Page",
  24. "content":" Welcome to about page."
  25. }
  26. return render(request, "home_page.html", context)
  27.  
  28. def contact_page(request):
  29. contact_form = ContactForm(request.POST or None)
  30. context = {
  31. "title":"Contact",
  32. "content":" Welcome to the contact page.",
  33. "form": contact_form
  34. }
  35. if contact_form.is_valid():
  36. print(contact_form.cleaned_data)
  37. #if request.method == "POST":
  38. #print(request.POST)
  39. #print(request.POST.get('fullname'))
  40. #print(request.POST.get('email'))
  41. #print(request.POST.get('content'))
  42.  
  43. return render(request, "contact/view.html", context)
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. def login_page(request):
  51. form = LoginForm(request.POST or None)
  52. context = {
  53. "form": form
  54. }
  55. print("User logged in")
  56. #print(request.user.is_authenticated())
  57. if form.is_valid():
  58. print(form.cleaned_data)
  59. username = (form.cleaned_data).get("username")
  60. password = (form.cleaned_data).get("password")
  61. user = authenticate(username='john', password='secret')
  62. print(user)
  63. print(request.user.is_authenticated())
  64. if user is not None:
  65. #print(request.user.is_authenticated())
  66. login(request, user)
  67. #login(request, username=username, password=password)
  68. #context['form'] = LoginForm()
  69. return redirect("/")
  70. # A backend authenticated the credentials
  71. else:
  72. print("Error")
  73. return render(request, "auth/login.html", context)
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. def register_page(request):
  81. form = RegisterForm(request.POST or None)
  82. context = {
  83. "form": form
  84. }
  85. if form.is_valid():
  86. print(form.cleaned_data)
  87. return render(request, "auth/login.html", context)
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. def home_page_old(request):
  100.  
  101.  
  102. html_= """
  103. <!doctype html>
  104. <html lang="en">
  105. <head>
  106. <!-- Required meta tags -->
  107. <meta charset="utf-8">
  108. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  109.  
  110. <!-- Bootstrap CSS -->
  111. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  112.  
  113. <title>Hello, world</title>
  114. </head>
  115. <body>
  116. <div class='text-center'>
  117. <h1>Hello, world!</h1>
  118. </div>
  119. <!-- Optional JavaScript -->
  120. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  121. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  122. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  123. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  124. </body>
  125. </html>
  126.  
  127. """
  128. return HttpResponse(html_)
Add Comment
Please, Sign In to add comment