Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的 urlconf:
url(r'^homepage/?(?:.json)?', home),
在视图中,我想获取 url 的结尾。我认为这样的事情可能会奏效:
def home(request): if request.url.endswith('.json') return json_homepage() else: return render(request,'other.html')
我解决了这个匹配request.path_info
request.path_info
url(r'^homepage/?(?:\.json)?', home),
if request.path_info.endswith("json"): return home_json_render() else: return render(request, 'frontpage.html', params)