首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未成功注册的等待列表注册页面重定向

问未成功注册的等待列表注册页面重定向
EN

Stack Overflow用户
提问于 2014-05-24 16:24:04
回答 1查看 78关注 0票数 0

我正在尝试获取我的初学者Django应用程序http://chishenma.herokuapp.com/的索引页面,以允许用户使用他们所在的城市和电子邮件地址注册加入等待名单。我直接从http://chishenma.herokuapp.com/register/的注册页面(减去几个字段)中提取了代码,但即使注册页面正在工作,索引页面上的注册也不起作用。由于某些原因,URL变成了/waiting_list,但实际上并没有注册(我在admin中进行了两次检查,可以找到来自/register页面的注册),页面上或控制台上都没有错误。下面是views.py中索引和waiting_list视图的代码:

代码语言:javascript
复制
def index(request):
    # user_form = UserCreationForm()
    city_form = UserCityForm()
    waitlist_form = WaitlistForm()

    if request.method == 'POST':
        city_form = UserCityForm(request.POST)
        waitlist_form = WaitlistForm(request.POST)

    if city_form.is_valid() and waitlist_form.is_valid():
        list_item, created = add_to_waitlist(waitlist_form.cleaned_data['email'])

        return redirect(reverse('home'))

    return render(request, "chishenma/index.html", {
        'city_form': city_form,
        'waitlist_form': waitlist_form,
    })

def waiting_list(request):
    return render(request, 'registration/waiting_list.html')

以下是来自forms.py的表单:

代码语言:javascript
复制
class WaitlistForm(forms.Form):
    email = forms.EmailField(max_length=35)
    fields = ('user_email,')

class UserCityForm(forms.Form):
    user_city = forms.CharField(max_length=25, required=True)
    fields = ('user_city,')

下面是index.html模板:

代码语言:javascript
复制
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div data-role="page" id="home">

<!-- Header -->
<div data-role="header" data-position="fixed" style="background-color:#EEEEEE;" data-tap-toggle="false">
    <h1>Welcome to ChiShenMa!</h1>
</div><!-- /header -->
    <div data-role="content">
        <div id="user_area">
            {% if user.is_authenticated %}
                <p>Hello, {{user.username}}!</p>
            {% else %}
                <p>We can't wait to show you our app! Please fill in the information below to join our waiting list.</p>
            {% endif %}
        </div>
        {% if not authenticated %}
            <form action="{% url 'waiting_list' %}" method="post">
                {{ city_form.as_p }}
                {{ waitlist_form.as_p }}
                <input type="submit" value="Join waiting list"/>
                {% csrf_token %}
                </form>
        {% else %}
        <a href="{% url 'logout' %}">Logout</a>
        <!-- Footer -->
        <div data-role="footer" data-theme="a" data-position="fixed" style="background-color:#EEEEEE;" data-tap-toggle="false"> 
        <a href="{% url 'choose_category' %}" class="ui-btn ui-corner-all" style="background-color:#FFCC00; display:block; margin:5px;">Click here to find something to eat!</a>
        </div><!-- /footer --> 
        {% endif %}

下面是waiting_list.html模板:

代码语言:javascript
复制
{% extends "base.html" %}
{% load staticfiles %}
{% block title %}Waiting list{% endblock %}

{% block content %}
<div data-role="page" id="waiting_list" data-theme="a">

    <div data-role="header" data-position="fixed" style="background-color:#EEEEEE;" data-tap-toggle="false" data-add-back-btn="true">
        <h1>Waiting list</h1>
    </div><!-- /header -->
  <h1>Thank you for signing up for our waiting list</h1>
{% endblock %}

来自urls.py的适用URL:

代码语言:javascript
复制
url(r'^$', 'chishenma_app.views.index', name='home'),
url(r'^waiting_list/$', 'chishenma_app.views.waiting_list', name='waiting_list'),

当我在本地服务时,控制台中的错误:

代码语言:javascript
复制
[24/May/2014 16:22:03] "GET / HTTP/1.1" 200 5663
[24/May/2014 16:22:12] "POST /waiting_list/ HTTP/1.1" 302 0
[24/May/2014 16:22:12] "GET / HTTP/1.1" 200 5663

我做错了什么?

编辑:

我在我的表单中添加了"data-ajax='false'“,但是同样的事情发生了,除了这一次在终端中我得到了:

代码语言:javascript
复制
[24/May/2014 16:46:46] "POST /waiting_list/ HTTP/1.1" 302 0
[24/May/2014 16:46:46] "GET / HTTP/1.1" 200 5681
EN

回答 1

Stack Overflow用户

发布于 2014-05-25 00:20:16

这一行可能是您的问题所在:

代码语言:javascript
复制
<form action="{% url 'waiting_list' %}" method="post">

当提交表单时,POST被发送到waiting_list方法,该方法完全没有POST处理(来自您粘贴的内容)。相反,所有的POST处理都是基于索引的。

尝试将其更改为<form action="." method="post">,或者更具体地说,更改为<form action="{% url 'home' %}" method="post">。两者都应该将帖子发送到index,后者完成注册。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23842880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档