0

I am new to Django and I am stuck with this issue. I am trying to create a login page where the user enters his/her username and password and Submit to go to the next page. For now just to test, I want to print a text saying " successfully logged in" when the user enters id and password in my login page itself.

This is my urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('login',views.log, name = 'login'),

]

This is my Views.py

from django.shortcuts import render

def log(request):
    return render(request, 'login_page.html')

def verify_num(request):
    username = request.GET['uname']
    password = request.GET['pass']
    grant = 'successfully logged in'
    if username == 'harish' and password == 'harish':
        return render(request, 'login_page.html',{'access':grant})

And this is my html page.

{% extends 'base.html' %}

{% block content %}
    <h1 align = 'center'><b>LOGIN</b></h1>


        <form action = '' align ='center'>

            Enter Username: <input type = 'text' name = 'uname' text-align :'center'><br><br>
            Enter Password: <input type = 'password' , name = 'pass' align = 'center'><br><br>
            <input type= 'submit'><br>
            <h3 >{{access}} </h3>
        </form>


{% endblock %}

How do I call my funtion verify_num in views.py so that the text saying "Successfully logged in" prits

  • Does this answer your question? [django: taking input and showing output in the same page](https://stackoverflow.com/questions/14837312/django-taking-input-and-showing-output-in-the-same-page) – sameera lakshitha Jan 01 '20 at 10:19
  • No, he is using another approach which I am not able to understand – GoldParticle Jan 01 '20 at 10:26

1 Answers1

0

I think what you are looking for is "messages".

https://docs.djangoproject.com/en/3.0/ref/contrib/messages/#using-messages-in-views-and-templates

You can add a message success message after successful form submit and show it on the next page. But if you want to show it without changing/reloading the page, you should deal with JSON views and query them with Javascript.

ulgens
  • 199
  • 1
  • 3
  • 11