Discussion:
need help on form view
Tosin Ayoola
2018-11-23 09:21:06 UTC
Permalink
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
--
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.
Yavin Aalto Arba
2018-11-23 13:20:52 UTC
Permalink
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.
Post by Tosin Ayoola
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
create_user = UserCreationForm(request.POST or None)
create_user.save()
return redirect(reverse('schoolprofile1'))
return render( request, 'create_user_form.html',
{'create_user': create_user,
})
school_info = SchoolsForm(request.POST or None )
request.session['school_data'] = school_info.cleaned_data
return redirect(reverse('schoolprofile2'))
return render(request, 'schoolprofile1.html',{
'school_info': school_info,
})
school_info_two = SchoolDataForm(request.POST)
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
--
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
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
<https://groups.google.com/d/msgid/django-users/CAHLKn73kTShkC7NsertLBbvrMnDp%3DJNQ0w2_iN41s-fVDiyRHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CA%2B%2Be-ZVDX%2BdzyJ4fJ2L7sKvDsDaOWJYKjUfRGTsROtGyxcEBwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Pradeep Singh
2018-11-23 17:56:46 UTC
Permalink
how to use javascript in django...please tell me
Post by Yavin Aalto Arba
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.
Post by Tosin Ayoola
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
create_user = UserCreationForm(request.POST or None)
create_user.save()
return redirect(reverse('schoolprofile1'))
return render( request, 'create_user_form.html',
{'create_user': create_user,
})
school_info = SchoolsForm(request.POST or None )
request.session['school_data'] = school_info.cleaned_data
return redirect(reverse('schoolprofile2'))
return render(request, 'schoolprofile1.html',{
'school_info': school_info,
})
school_info_two = SchoolDataForm(request.POST)
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
--
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
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
<https://groups.google.com/d/msgid/django-users/CAHLKn73kTShkC7NsertLBbvrMnDp%3DJNQ0w2_iN41s-fVDiyRHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
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/CA%2B%2Be-ZVDX%2BdzyJ4fJ2L7sKvDsDaOWJYKjUfRGTsROtGyxcEBwQ%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CA%2B%2Be-ZVDX%2BdzyJ4fJ2L7sKvDsDaOWJYKjUfRGTsROtGyxcEBwQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CANwgZcZR-VKJR58cXHBpCp8XRboBq6%2BbrTzi37rO4eaAH8NcBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Kasper Laudrup
2018-11-23 19:26:37 UTC
Permalink
Hi Pradeep,
Post by Pradeep Singh
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
--
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/2e43fe7c-0380-ca99-eb60-de86ada62090%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...