简体   繁体   中英

Django SessionWizardView get_template_names() issue

If I use the template_name variable, my SessionWizardView works like a pycharm!

I am having troubles with the get_template_names() method provided by the SessionWizardView.

My first template using the get_template_names() method renders perfectly displaying the correct url.

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

I submit the form, and my second form using the get_template_name() method renders perfectly displaying the correct url and form.

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

I submit my second form, or if I press the prev step or first step, the following url is displayed

http://127.0.0.1:8000/character_creation/

Here is the error message:

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

Anyone having a reason why the /wow/ part of my url has been removed when submitting the second form? Is there a bug in the get_template_names() method?

Here is my views.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/')

Here is my url.py

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

Thank you guys!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM