0

I am making a simple website and It worked in localhost. however, when I deploy my website It came up with error. So, I googled the reason why my code doesn't work. Then, I realized that there are something wrong with my csrf stuff. but I don't really know how to fix it.

first, this is a part of my views.py

@csrf_protect
def register(request): 
    context = RequestContext(request)
    registered = False 
    ...

return render_to_response('mysite/register.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered},context) 

and this is my register.html

<html>

<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
    <link href="https://fonts.googleapis.com/css?family=Dosis&subset=latin,latin-ext" rel="stylesheet" type="text/css">
        <title>Regitser With PAM</title>
</head>

<body>
    <h1>Register With PAM</h1>
    {% if registered %}
        <strong>Thank you for registering!</strong>
        <a href = "/">Return to MainPage.</a><br />
    {% else %}
    <strong>Register here!</strong><br />

    <form id = "user_form" method = "post" action = "/register/" enctype = "multipar/form-date">

    {% csrf_token %}
        {{ user_form.as_p }}
        {{ profile_form.as_p}}

       <input type = "submit" name "submit" value = "Register" />
   </form>
   {% endif %}
</body>

when I was trying to register my own website it always came up with this error

Forbidden (403)

CSRF validation failed
logan shin
  • 43
  • 2
  • 6
  • http://stackoverflow.com/a/12712507/1994255 See here. You need to check your production settings. – Lawrence Dean Vanderpool Aug 16 '16 at 17:57
  • At first you should fix your HTML. I don't know if all browsers get the extra spaces around the `=`, but at least the submit button has bad code. Then check if the token is actually rendered into the HTML code. – Klaus D. Aug 16 '16 at 18:00

0 Answers0