【发布时间】:2015-05-02 22:34:37
【问题描述】:
我们的基本网址是so.com
因此,如果 URL 以 abc 开头,例如
so.com/abc/
so.com/abc/123
so.com/abc?newtab=123
so.com/abc#123
so.com/abc/123?tab=new
...
那么所有这些 URL 模式都应该转到 Class Abc
myapp/urls.py
...
url(r'^abc[a-zA-Z0-9=#_\?\-/]+$',views.Abc.as_view(),name='abc')
myapp/myviews/abc.py
class Abc(View):
def get(self,request):
...
def foo(user_id):
...
def bar(post_id):
...
在函数get(self,request): 中如何获取请求的 abc 之后的所有内容。
例如
so.com/abc/xyz => /xyz
so.com/abc#123 => 123
so.com/abc?tab=new => ?tab=new
so.com/abc/123?tab=new => tab = new and 123
#123 加在 abc 之后会自动转换成abc/#123
如何完成这项工作?
我看过很多问题,但都没有帮助。
How to get the current URL within a Django template?
...
【问题讨论】:
标签: python regex django url model-view-controller