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 :

http://127.0.0.1:8000/!xyz

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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -