I have this form that includes around 25 inputs on the same. It includes a main image input and the rest are some text inputs or drop down menus.
The problem is that I also need the user to upload multiple images. I was thinking of doing it on the next page itself.
I have 2 questions:
What is the best way for adding this multiple image upload form to the current form? Not related to Django, more related to the structure of the form.
What is the best way of adding a multiple image/file to work correctly with Django? Any libraries or modules for such a job or any manual way to do it.
With formsets you allow the user to create several images at once. To create a formset out of an ImageForm you would do:
>>> from django.forms.formsets import formset_factory
>>> ImageFormSet = formset_factory(ImageForm)
https://docs.djangoproject.com/en/1.5/topics/forms/formsets/
And Django comes with an optional “form wizard” application that splits forms across multiple Web pages. It maintains state in one of the backends so that the full server-side processing can be delayed until the submission of the final form.
https://docs.djangoproject.com/en/1.5/ref/contrib/formtools/form-wizard/
Related
I want to make something like google forms which users can make themselfs. I want just simple html string forms which can reveal answer and check is it right instantly. No matter how users will create forms, but only using webpage. Without additional connecton to DB. Using only one field in column in DB.
Maybe forms can be like this using just html (best variation)
I'm creating a single page application in Django.
It mainly consists of multiple, small forms that are filled in and validated independent from each other. Every form looks similar to this:
With a final button press at the end though, the input of all those forms should be processed together.
How can I save/cache all data of the submitted forms to process them with a final form submit at the end?
I tried creating only one big form, but then I can't validate each field one after the other, when the user clicks the 'Next' button.
If you want to have a form spread across multiple pages with multiple request/response cycles I'd probably recommend storing it either in the session or in the database. The session is probably easier whereas the database approach is more sophisticated. You can store items in the session using request.session['step_1'] = {} for example.
So I'm trying to learn Django by building a very simple single-page site that just takes emails for subscriptions and stores it into djangos backend. I made an html page for the site that has form and input elements, and I've successfully rendered the page by following the documentation. I even built a model called 'subscriptions', to take email strings, but now i'm unsure about how to handle the input from the html page and store the emails in the backend.
All the documentation is kind of confusing cause it instructs me to build a separate .html file for the form, and handle it in another views and model page, which just seems unnecessary.
Does django necessitate handling input in a separate forms.html file? Or can i just use the index.html, and add views to 'views.py' or revise 'models.py'?
I'm pretty confused, all help and examples are very appreciated!
Django documentation on Working with forms mentions a lot of examples around what you want to do.
Create a forms.py as mentioned on the page and you can create an equivalent view for it in views.py which recieves form values.
Once you have your form data in the view as shown in example, you can save it to using, as something like:
s = Subscriptions(email=email)
p.save()
Refer more on models here.
I am looking for ways to best handle a single form on multiple pages. Like how a newsletter signup might be on a home page, an about page, and several blog pages.
I've handled this exact scenario in these 2 ways.
Write an API (using DRF) that takes a POST request, and then point the normal HTML form at that API. This works, and is very flexible, but feels like overkill.
Pass the form object into the context of each view I want the form to be on, and then include that into the template with includes form_snippet with form=form
The first approach is more flexible with wagtail, wherein all that needs to happen on the admin side is an inclusion of the newsletter as a snippet, where the admin user is able to choose if they want the newsletter on the page or not.
While both approaches work just fine, neither of them "feels" right, as I would think there is a simple way to do this without creating a big API, or passing around the form object to every single view.
three years later on you probably found an answer.
For documentation purposes and Google searchers, Wagtail offers an explanation on how to make a multiple step form here:
https://docs.wagtail.org/en/v3.0.1/reference/contrib/forms/customisation.html#multi-step-form
I did this with a contact formular. I handled it with a new app for my contact formular.
In this contactApp is the templates/contactForm.html. To include this contactForm where I want I use {% include 'contact/contactForm.html' %} so it loads the contactForm.html from my app called contact.
I want to benchmark the performance of a template website on a modified kernel. I want to use a website template that has 2-3 tiers (frontend, database etc), logic to create users and some logic to store/modify data for each user.
A quick search did not reveal any useful results as of yet.
I've little experience in web development and was hoping that stackoverflow can point me to something useful.
I would suggest taking a look at the Django framework:
http://docs.djangoproject.com/en/1.3/intro/
http://www.djangobook.com/en/2.0/
Django operates using a three tiered (Model, Template, View) design. The Model is the database access layer and will enable you to validate and store information about your users. The Template is the 'presentation layer' that will both determine the layout of your page through html, but has access to your view and its variables. The View is the portion that will contain all of the logic for the page - in a way it works as a median between your model and your template. The url your user visits will determine which view function you load.
If you are interested in the admin capabilities of the framework, take a look at:
http://www.djangobook.com/en/2.0/chapter06/
You could simply download and run one of the sample django applications like:
http://code.google.com/p/django-voting/
or
https://github.com/scrum8/django-job-board/
Or you could just create a clean django project and turn on the admin console.