I've started one new django project. I've linked the HTML file in the django's admin page. When I click view site in the admin page the html file has open.
In this html file there is a register button. When I click it, the html form will open for fill the details to register for signup.
When I filled the details and click submit button, the python file (signup.py) has to show the data and save in db. But I got the error
"Page not found (404)
Request Method: GET
Request URL: http://10.95.228.84:8000/signup.py?CID=aasa&user_name=sadsad&User_email=sasa%40gmail.com&DOB1=2016-08-30&Password11=sasasa&Password12=sasasa&submit=submit"
Please let me know how to link this signup.py file with this html.
What's going on is that you have a GET request to a URL that happens to be named 'signup.py' followed by the form parameters. This is not how Django fundamentally operates. Django forms automatically 'takes care of' saving new entries into the database if the forms are valid (assuming you are using a correct model and ModelForms).
I can't tell what your models are like or your urls, but I would suggest:
1) Creating Models in models.py that accurately match what you are trying to save into your database (if you haven't already)
2) Creating a view in views.py and that will link to a template (that you will need to create) displaying the data that is being saved into your database
3) Creating a url for this new view you created in urls.py
4) Editing the view that is currently handling the signup form to redirect your your view if the form is valid.
I would suggest looking at the Django tutorial. Going through it once or twice will solidify the basic workflow of using Django. This tutorial also has a solid tutorial on simple forms.
Django Tutorial
Simple Django Forms
Related
I want to add some content on one of my Wagtail pages and I am trying to import that Wagtail page on all my other wagtail pages. The reason I am trying to do this is that if in the future I make a change on the content it should consistently reflect on all the other Wagtail pages.
Is there a way that I can import a Wagtail page on all my other Wagtail pages, if so please let me know.
Thanks in advance!
I have a website which has the following Configurations:
1) Django-2.0.8
2) Wagtail-2.2.4
A custom template tag is a good way to achieve this, as it provides a place to run custom Python code (for retrieving the necessary data) before outputting the results to the template, either directly as a string or by rendering a template. For example, if you had a footer_text field on a HomePage model, and wanted to display the footer text of the HomePage with slug 'home' on every page, you could define a custom tag as follows:
#register.inclusion_tag('myapp/includes/footer.html')
def footer():
homepage = HomePage.objects.get(slug='home')
return {'footer_text': homepage.footer_text}
You could also look at Wagtail's site settings module as a way to define global content to be re-used across a site (although it's missing a few features that you'd get from defining it on a page model, such as moderation workflow and revision history).
I'm building a webpage that use ModelForm with ManyToMany relations. The Admin of django has the useful RelatedFieldWidgetWrapper. It creates a + next to relationfields that, when pressed, opens a popup to create a related-object. Once the creation is made the main webpage (the one where we press the +) has the new item loaded.
Now, in my website I would like to have something similar, my questions are:
is it correct to use the RelatedFieldWidgetWrapper in a webpage outside admin?
how does the page autoloads the new content (this is mainly my curiosity)
any other applicable solution to have a handy form without requiring complex JS or several pages?
thanks
So I have a model class a form class and a views class.
I am having a hard time effectively explaining to someone how it works in the sense of a MVC framework. I am new to django and I have followed the documentation however, i cannot seem to explain it well enough.
To my understanding you create the model, which you pass into your form to create a form, then pass that into your view when you render onto an html page through context then you wait for a user to hit a submit button which returns the info via POST and then you catch that data in your view and go through the necessary steps to save the data. Am I missing anything?
In python models.py and the forms together are the controller in MVC since they contain the program logic and control saving objects in the DB, views.py file is showing the content of data, so it's the View. The Model is what django ORM handles for us. It stores the data and handles load/stores in the DB.
I am new to Django and trying to create a registration form for users. I want users to upload there image during signup. After some research I got django-avatar and easy thumbnail as way to go, am I correct? So I went ahead with django-avatar but I am confused how to add a form field to userprofile that talks to django avatar. Am I in correct path or should I use some other plugin for uplaoding an user image. If Django-avatar is the way to go how should I create a form field for image and how my view look like?
Try using Formsets with the form set to avatar.forms.UploadAvatarForm
I'm in my first week of Django development and am working on an admin page that will let me write some quick html using TinyMCE and then save it to the database. I don't need to display this web page on the site or add it to urls.py, etc. The html snippet will be loaded from the database and used in a view function.
I've read in "Practical Django Projects" how to integrate TinyMCE, so my question is more concerned with the best approach for the form itself. Specifically:
1. Is there a built-in form like flatpage that works well for this? I only need one field in the form for the html.
2. How do I save the form's text after it's entered?
I created a model with a JSONField to save the html in, but I'm not clear on what to do next. Thanks.
here is the documentation for Django Flatpages App, maybe you serve.
I ended up using the ModelAdmin class to get what I wanted. I created a new model in models.py and then used ModelAdmin to enable an admin-editable form for the model's data.
Hope this helps someone.