【问题标题】:Django SessionWizardView get_template_names() issueDjango SessionWizardView get_template_names() 问题
【发布时间】:2015-03-04 12:05:24
【问题描述】:

如果我使用 template_name 变量,我的 SessionWizardView 就像 pycharm 一样工作!

我在使用 SessionWizardView 提供的 get_template_names() 方法时遇到问题。

我使用 get_template_names() 方法的第一个模板完美地显示了正确的 url。

http://127.0.0.1:8000/wow/character_creation/

我提交了表单,我使用 get_template_name() 方法的第二个表单完美地显示了正确的 url 和表单。

http://127.0.0.1:8000/wow/character_creation/

我提交了我的第二个表单,或者如果我按上一步或第一步,则会显示以下网址

http://127.0.0.1:8000/character_creation/

这是错误信息:

Page not found (404)
Request Method:     POST
Request URL:    http://127.0.0.1:8000/character_creation/

在提交第二个表单时,有人知道我的网址的 /wow/ 部分已被删除吗? get_template_names() 方法中是否存在错误?

这是我的意见.py

FORMS = [
("0", wow.forms.CharacterCreationForm1),
("1", wow.forms.CharacterCreationForm2),
("2", wow.forms.CharacterCreationForm3),

]

TEMPLATES = {
"0": "wow/character_creation_form_1.html",
"1": "wow/character_creation_form_2.html",
"2": "wow/character_creation_form_3.html",

}

class CharacterWizard(SessionWizardView):
    instance = None
    #template_name = "wow/character_creation_form_1.html"

# Requires the user to be logged in for every instance of the form wizard
# as-view() *urls.py* creates an instance called dispatch().  Dispatch is used to relay information
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
    self.instance = CharacterCreation()
    return super(CharacterWizard, self).dispatch(request, *args, **kwargs)

def get_form_instance(self, step):
    return self.instance

def get_template_names(self):
    #Custom templates for the different steps
    return [TEMPLATES[self.steps.current]]

def done(self, form_list, **kwargs):
    self.instance.character_creation_user = self.request.user
    self.instance.save()
    return HttpResponseRedirect('/wow/home/')

这是我的 url.py

url(r'^character_creation/$', CharacterWizard.as_view(FORMS), name='character_creation'),

谢谢你们!

【问题讨论】:

  • 网址格式中没有/wow/。那是基本的 URLs.py,还是包含它?
  • 如果你修正了缩进,你的问题会更清楚。
  • 还有,第一个和第二个模板的内容是什么?

标签: django django-views django-urls


【解决方案1】:

在我的第二个和第三个模板中,我的表单现在是 action="/character_creation/" 而不是 /wow/character_creation/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 2014-11-25
    • 2014-05-02
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    相关资源
    最近更新 更多