-1

I am very new to django. i am trying to create a login form in django but when i write the csrf_token line after the tag it is showing in the browser view. everything is very confusing for me i don't know what to do. the tutorial that i watch on youtube only pass the csrf_token but don't say anything much.

<form class="bg-white shadow-2xl rounded px-8 pt-6 pb-8 mb-4" action="Dashboard.html" method="POST">
            
            <img src="user.png" alt="user" class="flex h-30 w-40 mx-auto">
            {% csrf_token %}
            <div class="mb-4">
                <label class="block text-gray-700 text-sm font-bold mb-2" for="email">
                    Email
                </label>
                <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="email" type="text" placeholder="Email">
            </div>                         
            <div class="mb-6">
                <label class="block text-gray-700 text-sm font-bold mb-2" for="password">
                    Password
                </label>
                <input class="shadow appearance-none border rounded w-full py-2 px-5 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline" id="password" type="password" placeholder="Password">
            </div>
            <div class="flex items-center justify-between">
                <button class="bg-blue-950 hover:bg-blue-700 text-white font-bold py-2 px-8 rounded focus:outline-none focus:shadow-outline" type="submit" onclick="Submit_Click">
                    Sign In
                </button>
            </br>
            <a href="/change-password" class="text-blue-950 hover:text-blue-700">Change Password</a>
            </div>
        </form>

enter image description here

this is a very simple form that i styled using tailwindcss and the csrf token is being shown. also my app has other errors. it does not run on the development server

1 Answer 1

0

Did you edit your settings.py? Did you put {% csrf_token %} inside <form></form> ? 3 things comes to my mind is:

  1. check your settings.py for MIDDLEWARE and check if you have'django.middleware.csrf.CsrfViewMiddleware'.
  2. Check your template to see if you placed {% csrf_token %} inside your form.
  3. Check settings.py TEMPLATES section BACKEND if you have changed template engine. If you are using a custom template engine make sure it supports rendering this.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.