[英]What does it mean by object not reversible Django
I'm just trying to make a simple connection to another page using the url tag in Django.我只是想使用 Django 中的 url 标记与另一个页面建立简单的连接。 I'm getting a error of "'set' object is not reversible".
我收到“'set' 对象不可逆”的错误消息。 After searching for a bit I've been unsuccessful in finding anything.
在搜索了一下之后,我没有找到任何东西。
urls.py网址.py
from django.conf.urls import url
from . import views
APP_NAME = 'website'
urlpatterns = {
url(r'^$', views.admin_view, name='adminview'),
url(r'^eventview/$', views.event_view, name='eventview'),
}
admin_view.html admin_view.html
<!DOCTYPE html>
<html lang="en" >
<head>
{% load static %}
{% block header%}
{% include 'website/header.html' %}
{% endblock %}
<!-- Insert custom css here -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!-- top navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Vivid Fireworks</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="{% url adminview %}">Dashboard</a></li>
<li><a href="{% url eventview %}">Add Show</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
</div>
</div>
</nav>
I haven't ran into this problem before and it seems like it'll be a simple fix just something I'm over looking.我以前没有遇到过这个问题,看起来这将是一个简单的修复,只是我正在寻找的东西。 Any help is appreciated.
任何帮助表示赞赏。
urlpatterns
should be a list [...]
. urlpatterns
应该是一个列表[...]
。 You currently have a set {...}
.您目前有一个 set
{...}
。 It should be:它应该是:
urlpatterns = [
url(r'^$', views.admin_view, name='adminview'),
url(r'^eventview/$', views.event_view, name='eventview'),
]
In the template, you should use quotes when the url pattern name is a string:在模板中,当 url 模式名称是字符串时,您应该使用引号:
{% url 'adminview' %}
{% url 'eventview' %}
If you want to use namespaces, then app_name
should be lowercase.如果你想使用命名空间,那么
app_name
应该是小写的。
app_name = 'website'
url_patterns = [
...
]
You then need to include the namespace when you use the url tag然后需要在使用 url 标记时包含命名空间
{% url 'website:adminview' %}
{% url 'website:eventview' %}
在 URLpatterns 中,将 {} 更改为 [] 即可解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.