Django admin return to page after save - django

I have 3 pages of items listed in my django application admin. After i edit one of them (lets say it is in page 2) and save my changes, i return to page 1 of my listing. How can i make it so i return to the page the item is in?
I looked into some similar questions here at stackoverflow and i believe that i need to use javascript to send a httpresponse with the location header. But how i can determine the page the item is in?
any help is appreciated

You can find a code snippet in comments for this django ticket: http://code.djangoproject.com/ticket/3777

Related

How to import a Wagtail page on all the other wagtail pages

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).

Duplicate Title Tags with Django Pagination

I've recently deployed my website infortion. On the home page, I've used the django pagination so that users can see more content.
Few days ago I connected the site to webmasters & it's showing an error Duplicate title tags in the HTML improvements section.
Problem is coming from the home page because pagination is taking the users to next page but still keeping the same title. Which means these two pages,
/
/?page=2
will have the same title.
How can we solve this problem? Thank You.
Add a place for a title in your template and override that when passing it your context in the view.

How to link python file with the html file

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

Django with Jeditable: POST renders the whole page into table cell

use case:
user click on comment column to leave a comment.
comment is sent via post to the server.
server uploads to the database.
however instead of merely updating the page, Django puts my whole page into the into the table cell
before:
http://i50.tinypic.com/28cdkb7.jpg
after:
http://i45.tinypic.com/346vuag.jpg
http://formerlyconversal.wordpress.com/2009/11/01/inline-editing-with-jquery-jeditable-and-django/
you are probably looking for this.

Django form to enter/save html to database

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.