python - Use different view in Django if the url contains specific character -
i have view:
def url_redirect(request,id): url = get_object_or_404(url,short_id=id) return httpresponseredirect(url.httpurl)
and these urls:
urlpatterns = [ url(r'^admin/', admin.site.urls), url(ur'^(?p<id>.*)$', views.url_redirect), ]
basically redirecting http://127.0.0.1:8000/xyz different site
now have possibility use different view if url varies adding "!" character, i.e :
so whenever use url else redirecting.
any idea how can this? appreciated.
if want deal in same view, leave urls
, change view:
def url_redirect(request,id): if id.startswith('!'): id = id[1:] # whatever want id else: url = get_object_or_404(url,short_id=id) return httpresponseredirect(url.httpurl)
Comments
Post a Comment