0

I have been using Django successfully for a few days now. I was running my django application on an Amazon Web Service machine. I was assigned some arbitrary DNS name that looked like this: http://ec2-XXX.XXX.XXX.XXX.compute-1.amazonaws.com. My Django app was working find with my model and several views with templates.

Last night, I went out and bought a real DNS name from register.com and have that DNS name now pointing to my django application. Since I made that change however, when I submit my django form, I get the following CSRF error:

Forbidden (403) CSRF verification failed. Request aborted.

I tried clearing the cookies in my browser, but that didn't help. I even tried it from other machines that I had never tried before. But still the same problem. Why did assigning a new DNS name for this IP address cause this CSRF error? And how do I get rid of it?

My form:

<form action="/forgotUserName2" method="post">{% csrf_token %}

<label for="id_email">E-mail:</label></th><td><input id="id_email" type="text" class="required" name="email" maxlength="75" />
<input type="submit" value="Submit" />
</form>
4

1 回答 1

0

尝试将文件中的CSRF_COOKIE_DOMAIN设置设置settings.py为新域名。

另外,顺便说一句,您的操作名为/forgotUserName2. forgot_user_name_2python中的方法和函数通常是这样的:蛇壳。此外,django 中的 URL 应始终以斜杠结尾:/forgot_user_name_2/.

于 2013-01-09T00:37:34.483 回答