我创建了以下 URL:
urls.py
url(r'^authors', GenericView.as_view(model=Author, context_object_name='authors_list',
success_url=reverse_lazy('author_link'),
template_name='app/authors.html'), name='author_url_name'),
我想访问 View 上的 URL 名称,并传入变量。在本例中,为'author_url_name'。
我需要的 View 函数如下:
views.py
def get_context_data(self, **kwargs):
context = super(AuthorClass, self).get_context_data(**kwargs)
context['action'] = reverse_lazy('author_url_name')
return context
这可行,但我想用某种方法替换“author_url_name”,从而为我提供准确的信息。
感谢您的宝贵时间!!
最佳答案
https://stackoverflow.com/a/17614086/183948已为您解答。
As of Django 1.5, this can be accessed from the request object
current_url = request.resolver_match.url_name
https://docs.djangoproject.com/en/1.5/ref/request-response/#django.http.HttpRequest.resolver_matc
关于python - Django - 将 URL "name"属性传递给 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25044066/