redirect

How to pass context data with django redirect function?

How to pass context data with django redirect function? Question: I have function which redirect to a URL. return redirect(‘/orders’) The URL /orders has some context data which is being passed to it. I want to pass some additional data along with data from the URL’s function in view like: return redirect(‘/orders’, {‘message’:’some_message’}) I tried …

Total answers: 4

Python – Send HTTP GET string – Receive 301 Moved Permanently – What's next?

Python – Send HTTP GET string – Receive 301 Moved Permanently – What's next? Question: I’m trying to use Python 2 to send my own HTTP GET message to a web server, retrieve html text, and write it to an html file (no urllib, urllib2, httplib, requests, etc. allowed). import socket tcpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) …

Total answers: 3

Redirect to other view after submitting form

Redirect to other view after submitting form Question: I have a survey form. After submitting the form, I’d like to handle saving the data then redirect to a "success" view. I’m using the following code right now, but it just stays on the current url, while I’d like to go to /success. How can I …

Total answers: 2

Redirecting a View to another View in Django Python

Redirecting a View to another View in Django Python Question: How does one redirect from one View to another (next-going one): class FooView(TemplateView): template_name ‘foo.html’ def post(self, *args, **kwargs): return redirect(BarView) # return redirect(BarView.as_view()) ??? class BarView(TemplateView): template_name ‘bar.html’ Asked By: 0leg || Source Answers: Give the URL pattern itself a name in your urls.py: …

Total answers: 3

Http Redirection code 3XX in python requests

Http Redirection code 3XX in python requests Question: I am trying to capture http status code 3XX/302 for a redirection url. But I cannot get it because it gives 200 status code. Here is the code: import requests r = requests.get(‘http://goo.gl/NZek5’) print r.status_code I suppose this should issue either 301 or 302 because it redirects …

Total answers: 4

Flask redirecting multiple routes

Flask redirecting multiple routes Question: I’m trying to implement a redirecting pattern, similar to what StackOverflow does: @route(‘/<int:id>/<username>/’) @route(‘/<int:id>/’) def profile(id, username=None): user = User.query.get_or_404(id) if user.clean_username != username: return redirect(url_for(‘profile’, id=id, username=user.clean_username)) return render_template(‘user/profile.html’, user=user) Here’s a simple table of what should happen: URL Redirects/points to ==================================================== /user/123 /user/123/clean_username /user/123/ /user/123/clean_username /user/123/foo /user/123/clean_username /user/123/clean_username …

Total answers: 4

Make a POST request while redirecting in flask

Make a POST request while redirecting in flask Question: I am working with flask. I am in a situation where I need to redirect a post request to another url preserving the request method i.e. “POST” method. When I redirected a “GET” request to another url which accepts “GET” request method is fine. Here is …

Total answers: 1

Redirecting to URL in Flask

Redirecting to URL in Flask Question: I’m trying to do the equivalent of Response.redirect as in C# – i.e.: redirect to a specific URL – how do I go about this? Here is my code: import os from flask import Flask app = Flask(__name__) @app.route(‘/’) def hello(): return ‘Hello World!’ if __name__ == ‘__main__’: # …

Total answers: 11

Django redirect to view

Django redirect to view Question: I have a view that I then want to redirect to another view with a success message. The signature of the method that I want to redirect to is: quizView(request, quizNumber, errorMessage=None, successMessage=None) And my attempt at redirecting to that view is: return redirect(quizView, quizNumber=quizNumber, errorMessage=None, successMessage="Success!") I’ve tried almost …

Total answers: 4

What the difference between using Django redirect and HttpResponseRedirect?

What the difference between using Django redirect and HttpResponseRedirect? Question: Which is it better to use generally? https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect Is there any advantage to writing: return redirect(my_url) over: return HttpResponseRedirect(my_url) Or is it a direct alias? Is there any difference? Which is more pythonic/django-nic? Asked By: Williams || Source Answers: From documentation – redirect(to[, permanent=False], …

Total answers: 2