28👍
✅
instead of
return HttpResponseRedirect('news:home',request)
this:
return HttpResponseRedirect(reverse('news:home'))
or
return redirect('news:home')
or
return redirect(reverse('news:home'))
- Deploying django by python manage.py runserver to production on VPS
- Django database synchronization for an offline usage
- Disable pylint warning E1101 when using enums
6👍
In addition to the current answers if you want to redirect to an custom scheme, you can use following code:
class CustomSchemeRedirect(HttpResponsePermanentRedirect):
allowed_schemes = ['tg']
def redirect(request):
return CustomSchemeRedirect('tg://resolve?domain=durov')
- Remove autofocus attribute from field in Django
- What is the main difference between clean and full_clean function in Django?
3👍
Make sure that when you get this error you have the correct scheme supplied in front of your URL. By default the django.http.HttpResponseRedirect
does not allow redirects to URLs that don’t start with one of the following schemes:
- http
- https
- ftp
So if the URL you supply is, for example, localhost:8000
make sure you change it to http://localhost:8000
to get it to work.
👤Bono
- How do I set HttpOnly cookie in Django?
- How to test django caching?
- Token Authentication Django Rest Framework HTTPie
- How to solve PytestConfigWarning: Unknown config option: DJANGO_ SETTINGS_MODULE error?
- Django: how to get field by field name from Model instance dynamically?
0👍
Don’t forget that apart from enabling the redirect, nowadays Safari won’t open your redirected deep links unless you do the work outlined here: https://developer.apple.com/documentation/xcode/supporting-associated-domains
- Add the url path into your Django app:
path('.well-known/apple-app-site-association', views.web.links.appleAppSiteAssociation, name='.well-known/apple-app-site-association'),
- The view should return a JSON response:
def appleAppSiteAssociation(request_):
"""
Tell Apple that certain URL patterns can open the app
:param request_:
:return:
"""
json = {
"applinks": {
"details": [
{
"appIDs": ["MY.APP.BUNDLEID"],
"components": [
{
"#": "no_universal_links",
"exclude": True,
"comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"
},
{
"/": "/dataUrl=*",
"comment": "Matches any URL whose path starts with /dataUrl="
},
]
}
]
},
"webcredentials": {
"apps": ["MY.APP.BUNDLEID"]
},
}
return JsonResponse(json)
- Add the
webcredentials:MYPROTOCOL
into the Associated Domains in XCode
- Different sessions for admin and applications in Django
- Generate unique hashes for django models
- Changing password in Django Admin
Source:stackexchange.com