What does it mean by object not reversible Django

Question:

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.

Asked By: Joshua de Leon

||

Answers:

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'),
]

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

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

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

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

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

{% url 'website:adminview' %}
{% url 'website:eventview' %}
Answered By: Alasdair
  • **Change url to path if you have django version 2.0 **
Answered By: Adil Shehzad

in URLpatterns, make the change from {} to [] that will solve

Answered By: Igor Freitas

Changing in urls.py

From { and ending with } sign to start with [ and end with ] helps!

from django.contrib import admin
from django.urls import path

from TheB.views import index, about

urlpatterns = [
    path('', index, name='index'),
    path('about/', about, name='about'),
    path('admin/', admin.site.urls),

]

This is what helped me!

Answered By: MilanovicFUL
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.