In a form submission script, the form presents a message for "/ submit". I want to redirect the user to "/ sucess" for success and pass the rendering of some message to the template with the new URL. How to do it in Django? render_to_response does not redirect, and HttpResponseRedirect does not render templates.
If your success page needs a dynamic message, you need to convey it somehow. You can do this by using the GET parameters in the URL you are redirecting to, for example return HttpResponseRedirect('/success/?msg=My+success+message+here'), or by setting some values in the session that the success representation may display.
return HttpResponseRedirect('/success/?msg=My+success+message+here')
A response from Daniel Roseman is potentially dangerous by opening your site for XSS vulnerabilities.
Make sure you separate the html tags from any post if you should do it this way.
A better way would be to redirect to / success /? msg = ok and have a dictionary in your dictionary:
{ 'ok': 'Your success message' }
, : , ( ) dict. render_to_response .
, , .
: :
if anyError: dict = {"message" : {"error" : "The error message"}} else: dict = {"message" : {"success" :"The success message"}}
:
{% if message %} {% if message.error %} {{ message.error }} {% else %} {{ message.success }} {% endif %} {% endif %}
,
, . , /. , "", ; . , , . , , POST .
. , - .
, Django , . "post_save_redirect". Django. , , , , URL- "/user/add". "/user/1" " № 1". , , , . Django python, Django, , , .
I would recommend using the Django messaging environment, which is used for one-time notifications.
https://docs.djangoproject.com/en/1.8/ref/contrib/messages/
Source: https://habr.com/ru/post/1725406/More articles:TTabControl: tabs are displayed from right to left - delphiWhen I deploy code through GoogleAppEngineLauncher, does it download all the files? - google-app-enginedjango use settings.py elsewhere - djangoIs it possible to always use INSERT .... ON DUPLICATE UPDATE for simple updates / inserts? - sqlFire mouse event on basic components - javaЯвляется ли System.Guid.NewGuid() всегда реализованным через UuidCreate() в Windows? - windowsAutomatically create class diagram from ActionScript code? - actionscriptDoes if () use accepted practice in conjunction with immediate return? - language-agnosticSolving algebraic equation programs - matlabObjective-C init init method, how to avoid recursion? - objective-cAll Articles