Django'设置'对象是不可逆的。不知道为什么?

时间:2018-02-25 08:36:42

标签: django django-models django-rest-framework

我正在使用Django创建一个博客。我得到这个错误'set'对象是不可逆的。 请让我知道,为什么我遇到这个错误以及如何解决它?

TypeError at /admin/
'set' object is not reversible
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version: 2.0.2
Exception Type: TypeError
Exception Value:    
'set' object is not reversible
Exception Location: C:\Users\USER\Anaconda3\lib\site-packages\django\urls\resolvers.py in _populate, line 416
Python Executable:  C:\Users\USER\Anaconda3\python.exe
Python Version: 3.6.0
Python Path:    
['C:\\Users\\USER\\Desktop\\Django\\HarryBlog',
 'C:\\Users\\USER\\Anaconda3\\python36.zip',
 'C:\\Users\\USER\\Anaconda3\\DLLs',
 'C:\\Users\\USER\\Anaconda3\\lib',
 'C:\\Users\\USER\\Anaconda3',
 'C:\\Users\\USER\\AppData\\Roaming\\Python\\Python36\\site-packages',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages\\Sphinx-1.5.1-py3.6.egg',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages\\win32',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\USER\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg']
Server time:    Sun, 25 Feb 2018 08:31:27 +0000

这是我的 urls.py 文件:

from django.conf.urls import url
from django.contrib import admin
from django.urls import path , include
from . import views
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^about/$',views.about),
    url(r'^$', views.homepage),
    url(r'^Home/', include('Home.urls')),
]

1 个答案:

答案 0 :(得分:1)

from django.contrib import admin
from django.urls import path , include
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('about/', views.about), 
    path('', views.homepage, name="index"), 
    path('Home/', include('Home.urls')),
]

我这是因为你使用url而不是路径。在Django 2.0中,网址更改为path