python - Django,重定向的网址不正确

标签 python django

我是 Django 新手,我正在创建一个表单,

#forms.py
class SetupForm(forms.Form):
    pass

对应的 View 是

#views.py
class SetupView(FormView):
    template_name = 'template/setup_form.html'
    form_class = SetupForm
    success_url = 'template/base_collect'

    def form_valid(self,form):
        return super(SetupView, self).form_valid(form)

def base(request):
    return render_to_response('template/base_collect.html')

URL 模式是,

#urls.py
urlpatterns = patterns(url(r'^setup-form/$', views.SetupView.as_view(), name='setup-form'),
                   url(r'^base_collect/$', views.base),)

提交表单后,重定向的URL显示为

http://127.0.0.1:8000/template/setup-form/template/base_collect.html 而不是http://127.0.0.1:8000/template/base_collect.

我在这里缺少什么?后期如何实现?

最佳答案

修改如下:

#urls.py
urlpatterns = patterns(
    url(r'^setup-form/$', views.SetupView.as_view(), name='setup-form'),
    url(r'^base_collect/$', views.base, name = 'base-form'),
)

还有

替换

success_url = 'template/base_collect.html'

success_url = reverse('base-form')

导入

from django.core.urlresolvers import reverse

在你的观点中.py

关于python - Django,重定向的网址不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21898856/

相关文章:

python - 如何获取列表值的索引以及用户输入要选择的值

python - Django文件上传: Upload form has no save method

python - Django - 来自模板标签内变量的字符串

python - 如何在 Django 中调试失败的测试?

python - pip install 抛出值错误

python - 在没有 shell 窗口的情况下运行 shell 命令

python - 是否可以在 Django 模型中存储数组?

python - 具有多个服务类别的云端点

django - 返回 DRF 序列化程序中选择字段的人类可读元素

python - 如何在Django中正确显示ManyToMany ID匹配列表?