什么意思是对象不可逆Django [英] What does it mean by object not reversible Django

查看:187
本文介绍了什么意思是对象不可逆Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试使用Django中的url标签连接到另一个页面。我收到一个错误'set'对象是不可逆的。搜索一下后,我一直没有找到任何东西。

I'm just trying to make a simple connection to another page using the url tag in Django. I'm getting a error of "'set' object is not reversible". After searching for a bit I've been unsuccessful in finding anything.

urls.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

<!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 应该是一个列表 ...] 。您目前拥有一组 {...} 。它应该是:

urlpatterns should be a list [...]. You currently have a set {...}. It should be:

urlpatterns = [
    url(r'^$', views.admin_view, name='adminview'),
    url(r'^eventview/$', views.event_view, name='eventview'),
]

在模板中,当url模式名称为字符串时,应使用引号:

In the template, you should use quotes when the url pattern name is a string:

{% url 'adminview' %}
{% url 'eventview' %}

如果要使用命名空间,那么 app_name 应该是小写。

If you want to use namespaces, then app_name should be lowercase.

app_name = 'website'
url_patterns = [
    ...
]

当您使用url标签时,您需要包含命名空间

You then need to include the namespace when you use the url tag

{% url 'website:adminview' %}
{% url 'website:eventview' %}

这篇关于什么意思是对象不可逆Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆