wagtail-form-example | Django form on a Wagtail site | Form library
kandi X-RAY | wagtail-form-example Summary
kandi X-RAY | wagtail-form-example Summary
An example of implementing a Django form on a Wagtail site, without using the wagtailforms module.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a home page .
- Display search results .
- Serve suggestions .
wagtail-form-example Key Features
wagtail-form-example Examples and Code Snippets
Community Discussions
Trending Discussions on wagtail-form-example
QUESTION
I want to add a simple form to my Wagtail site, which will enable some users (with suitable permissions perhaps) to create a new page, outlining a game scenario. Just a title field and a rich-text field in other words.
Now I have read the docs at http://docs.wagtail.io/en/v1.10.1/reference/contrib/forms, which is close to what I need, except that the AbstractForm class or the like appears to be geared towards letting users design their own forms, which I do not want them to do. So the alternative is to use a standard Django form, as per the 'example' given at https://github.com/gasman/wagtail-form-example/commits/master. However I do not find that to be useful.
So my question is this: do I use a Wagtail form which (I presume) has the 'correct' page-handling code, or I do I somehow shoe-horn a Django form into my Wagtail site and hope that it integates well with the Wagtail stuff?
Alternatively, can I simply use the Wagtail form and prohibit users from modifying it?
On reflection, all I need to do (I think) is to define a new Page type! That will be a form of sorts, which I have confirmed by examining the source of a 'Create Event' page in the demo.
I still need a link/button to invoke an instance of the relevant model but that should not be a problem.
As I indicated earlier, this is largely due to ignorance of Wagtail on my part but somehow the usage is not that well explained, IMO.
...ANSWER
Answered 2017-Jun-04 at 12:17I would recommend going with Wagtail forms, here is why;
- Great support out of the box, easy reporting on submissions and email alerts.
- Good docs surrounding building a view for the form page and response pages, plus you can add some nice things to the form_page model like an intro paragraph.
- Better page handling as you mentioned, no need to work around how to put the form page in your existing site structure.
- All the benefits of normal pages such as searching, revisions/drafts, existing and using existing views.
Even if you might only (as the super admin) create one form (Game Scenario) it would still be worth it.
The page that is created can be viewed by anyone that views your site (or has access to viewing that page via the page permissions).
You can also record the user that submitted the form by following the instructions here:
Instructions on how to edit permissions, so that users with admin access cannot edit the form structure:
http://docs.wagtail.io/en/v1.10.1/topics/permissions.html
Additional Information
In reply to your questions/comments, for the sake of future viewers;
Submitted data storage All form submissions (aka responses) get stored in a form. submissions table that comes as part of the Wagtail forms module. You can define your own form submissions table if you need to extend the basic functionality.
Why there is not a page wrapper for Django forms? I am not sure on this one, the main reason is probably to provide basic user defined forms as part of the Wagtail admin UI. Internally, Django form fields are used but defined dynamically on the fly and submissions stored as JSON. The purpose again is to have simple user defined forms.
Creating a Page Type. Yes, this is how Wagtail approachesthe forms problem, a Form is just a page. This form page can exist anywhere you want it to in the page heiracy. This is different to Snippets for example, which are models used separately from Pages.
Linking to Form Pages As each form page is also just a page, you can create a link to it anywhere you can link a Page.
QUESTION
I followed the instructions on the Wagtail Form Example on Github to create standard Django forms outside of Wagtail. This worked perfectly, however there is a new issue now.
On the pages where there are forms, the standard Page-related template code in base.html no longer works, namely:
...ANSWER
Answered 2017-Jul-23 at 09:53You are using the variable self
in your template code, but there is no self
context variable being passed in the call to render
- only page
and form
.
Using self
in templates is discouraged, as it's incompatible with some template engines such as Jinja2. You should use page
instead:
QUESTION
I have a very interesting task.
- Wagtail Form with a FileField - For image upload (I guess this is not possible yet)
From the point that this is not possible yet in Wagtail I've tried another thing.
- A Django Form (from this example django form in wagtail) that has actually a FileField.
- Generate the link to uploaded image (let's say '/media/pics/image_example.jpg')
- Somehow pass this link (a text field) to Wagtail Form and auto-submit it.
So at the end, we have the Form Submissions in WagtailAdmin that has a field with the direct url to the uploaded image.
But.. I don't really understand how this must work. Any ideas? Maybe there are better solutions for my problem.
...ANSWER
Answered 2017-Apr-01 at 17:58Have a method as mentioned below
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wagtail-form-example
You can use wagtail-form-example like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page