python - How to redirect in django while using django-hosts? -


i'm using django-hosts package manage content that's supposed set in various different subdomains. started making view in form used change something. once form validated , processed, user supposed redirected other page. looking through documentation there's easy way render():

settings_url = reverse('settings', host='dashboard') return render(request, 'dashboard/settings.html', {'settings_url': settings_url}) 

however, there's no mention of redirect(). how go redirecting somewhere else, instead of usual return redirect("dashboard:settings")

myapp/hosts.py :

host_patterns = patterns('',     host(r'www', settings.root_urlconf, name='www'),     host(r'dashboard\.myapp\.com', 'dashboard.urls', name='dashboard'), ) 

dashboard/urls.py

from .views import home, websitesettings  urlpatterns = [     url(r'^$', home, name='home'),     url(r'^settings/$', websitesettings, name='settings'), ] 

basically want redirect same page after form submitted (in render example, i'm submitting form change website settings, model on it's own, , want redirect same page after that).

well took couple of different , convoluted tries, take night off , come solution that's ironically easy. use of dajngos native redirect django-hosts reverse function , works charm:

from django_hosts.resolvers import reverse  return redirect(reverse('home', host='dashboard')) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -