render_to_response or redirect changes the template elements in Django 1.8

别说谁变了你拦得住时间么 提交于 2019-11-28 13:00:05

1) Actually there are many ways to pass data to next view ... generally in such cases like you have better way - using sessions (cookie|localstorage|sessionstorage), it is like clipboard ... save session data in one view and get it later in another one. For example:

First view:

self.request.session['response_data'] = 'some text'
self.request.session.set_expiry(0)  # user’s session cookie will expire when the user’s Web browser is closed.

Other views:

response_data = self.request.session.get('response_data', '')

But if you planning just use this data in template Django has some kind more high-level interface for it and in your case semantically right to use it - The messages framework https://docs.djangoproject.com/en/1.8/ref/contrib/messages/

2) If you want redirect to another view better use url namespaces and reverse https://docs.djangoproject.com/en/1.8/ref/urlresolvers/#reverse

return HttpResponseRedirect(reverse(app.views.profile))  # here I've passed callable object because you have not show your app url namespace, but generally use namespaces

https://docs.djangoproject.com/en/1.8/topics/http/urls/#url-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!