0

I'm looking for a way to make a redirect from one url to another with query string parameter. Is it possible to get a redirect from /orders/ to /orders-new/?queryParam=1 How should I change RedirectView in a first line?

url(r'^orders/$', RedirectView.as_view(pattern_name='orders-new'),
    name='orders'),
url(r'^orders-new/$', orders_list_new, name='orders-new'),
2
  • Now what happens when you visit /orders/ ? Commented Aug 28, 2018 at 8:29
  • @MohitSolanki I get redirect to orders-new view without query string Commented Aug 28, 2018 at 9:40

2 Answers 2

2

Try to use url argument like this:

from django.urls import reverse_lazy

url(r'^orders/$', RedirectView.as_view(url='{}?queryParam=1'.format(reverse_lazy('orders-new'))),
    name='orders'),
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer, but I got the following error django.core.exceptions.ImproperlyConfigured: The included URLconf 'project.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
@DaniilMashkin try to move line with orders url under orders-new line.
@DaniilMashkin can you show content of project.urls file?
1

You can do one thing, For a quick solution Write a simple view for /orders/ url and in it's dispatch method redirect url to /orders-new/ with any string parameters You can redirect as below

def dispatch(self, request, *args, **kwargs):
    return redirect(reverse('<app_name>:orders')

2 Comments

And have to combine this solution with @neverwalkaloner answer to add query string param to url
Yeah, it looks dirty but internally ReditectView Work Like the same way I suggest you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.