need help on form view

21 views
Skip to first unread message

Tosin Ayoola

unread,
Nov 23, 2018, 4:22:16 AM11/23/18
to django...@googlegroups.com
Good day Guys,
working on a 3 step form but the issue now is that at the 2nd step the form instead of redirecting the user to the final step, it instead redirects back to the 1st step. below is my view, url code
#Views
def add_user(request):
create_user = UserCreationForm(request.POST or None)
if request.method == 'POST' and create_user.is_valid():
create_user.save()
return redirect(reverse('schoolprofile1'))

return render( request, 'create_user_form.html',
{'create_user': create_user,
})



def schoolprofile1(request):
school_info = SchoolsForm(request.POST or None )
if request.method == 'POST' and school_info.is_valid():
request.session['school_data'] = school_info.cleaned_data
return redirect(reverse('schoolprofile2'))

return render(request, 'schoolprofile1.html',{
'school_info': school_info,
})


def schoolprofile2(request):
school_info_two = SchoolDataForm(request.POST)
if request.method == 'POST' and school_data.is_valid():
complete_school_data_ = {
**request.session['school_data'],
**school_info_two.cleaned_data
}
Schools.object.create(**complete_school_data)

return redirect('schoolDetail')

return render(request, 'schoolprofile2.html',{
'school_data':school_info_two,
})

#URL

urlpatterns = [
path('', views.index, name = 'index'),
path('schoolprofile/step-two', views.schoolprofile2, name='schoolprofile2'),
path('schoolprofile/step-one', views.schoolprofile1, name = 'schoolprofile1'),
path('schoolprofile/add-user', views.add_user, name= 'add_user'),
path('schoolprofile', views.add_school, name='add_school'),
#path(r'ProfileYourSchool', add_School.as_view([profileForm, SchoolsForm, schoolDataForm]), name = 'add_Schools'),
path(r'ContactUs', views.Contact, name = 'Contact'),
]


thanks
Screenshot from 2018-11-23 09-03-06.png
Screenshot from 2018-11-23 09-06-58.png

Yavin Aalto Arba

unread,
Nov 23, 2018, 8:21:39 AM11/23/18
to django...@googlegroups.com
I think the problematic part is " create_user = UserCreationForm(request.POST or None)"

Most FBV for forms start with the "if request.method == 'POST" and then continue to fill the form. You can set the "None" after the if statement instead of before everything else.

I am not sure that the or NONE syntax is working properly in your usage for this. Could be wrong. I suggest to try using the boilerplate way.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn73kTShkC7NsertLBbvrMnDp%3DJNQ0w2_iN41s-fVDiyRHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Pradeep Singh

unread,
Nov 23, 2018, 12:57:39 PM11/23/18
to django...@googlegroups.com
how to use javascript in django...please tell me

Kasper Laudrup

unread,
Nov 23, 2018, 2:27:17 PM11/23/18
to django...@googlegroups.com
Hi Pradeep,

On 23/11/2018 18.56, Pradeep Singh wrote:
> how to use javascript in django...please tell me
>

You don't use javascript in Django. There are some Python modules for
executing javascript code from your Python code, but why would you want
to do that?

You're probably talking about writing javascript code that runs on the
client, but that is not directly related to Django, so this is really
not relevant here. Without any further information it's hard to know.

Start by reading this:

https://stackoverflow.com/help/how-to-ask

Then, when you've figured out how to formulate a useful question, start
a new thread instead of highjacking a completely unrelated one like
you've done here.

Kind regards,

Kasper Laudrup
Reply all
Reply to author
Forward
0 new messages