English 中文(简体)
Django为什么把我的形式转向不同于“行动”形式具体指明的不同地点?
原标题:Why is Django redirecting my forms to a different location than the form s "action" specifies?

我正在使用Django sdjango.contrib.auth.forms 模块,特别是UserCreationForm

这里是我表格的模板平均,register_formviews.py上的变量。 持有空洞的<代码>UserCreationForm:

<form  id="registration" method="post" action="/register">
    {% csrf_token %}
    <table class="float_left">
        <tr><th><label for="id_username">Username:</label></th><td>{{  register_form.username }}</td></tr>
        <tr><th><label for="id_password1">Password:</label></th><td>{{  register_form.password1 }}</td></tr>
        <tr><th><label for="id_password2">Confirm Password:</label></th><td>{{  register_form.password2 }}</td></tr>
    </table>
    <input class="float_right button_input" type="submit" value="Register" />
</form>

It displays just fine on the page. Note that the action is set to "/register". However, when I clicked on the submit button, nothing was happening. I opened up Chrome s ever-so-handy JavaScript console, and saw the following output (running on Django s manage.py dev server):

POST http://localhost:8000/includes/register.php 404 (NOT FOUND)

令人憎恶。 请注意,此处的Django(或别的,可能的话)已插入<条码>内含目录。

Here is the relevant snippet from urls.py:

urlpatterns = patterns(  ,
    url(r ^register ,  authentication.views.register ),
)

<代码>views.py:

def register(request):
# csrf is used to prevent Cross-Site Request Forgeries (i.e. XSS attacks, SQL injections, etc.)
c = {}
c.update(csrf(request))

# if logged in, redirect to personal profile
if request.method ==  POST :
    form = UserCreationForm(request.POST)
    if form.is_valid():
        new_user = form.save()
        return HttpResponseRedirect("/home")
else:
    c[ register_form ] = UserCreationForm()
    return render_to_response( authentication/register.html , c, context_instance=RequestContext(request))

如果该表有效(在数据库中拯救新用户后),或绕过同一页(authentication /register.html),则仅简单地转至/home

我亲爱。

事先感谢你能够告诉我的任何东西。

EDIT:我要指出,我一直在使用<编码>http:// localhost:8000/。 作为Django的田地,现在就投入了相当一段时间。 事实上,当我使用<条码>时,这种形式似乎也在做罚款。 用户CreationForm 载于as_table() 印刷方法。 但是,它看得很可怕,因此,我转而采用人工格式,现在它没有工作。 我没有调整<代码><form>。 在我之前,我仍不得不提供汽车印刷。

MAJOR EDIT:

<NEVERMINMIND GUYS, I GOT IT: 引人注意的是,在我开始将其转换为Django之前,有人试图将一些旧的营地称作作鉴定,而这是我以前所做的事。 由于这些评论,但Im gonna在结束这一问题。

问题回答

除非你另有明文规定,Django s devserver在127.0.0.1:8<000上为你的网页服务。

从您的POST URL I中,我只能猜测,你的一些PHP应用程序配置在http:// localhost:8000上,可能是通过Appa。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签