我的URLs.py
中有以下代码from django.conf.urls import url, include, path
from django.contrib import admin
urlpatterns = [
path('moraimono/', include('moraimono.urls')),
path('admin/', admin.site.urls),
然而我发现path()仅包含在Django 2.0中,我使用的是Django 1.11b1。
如何修改此代码以使其在Django 1.11b1中运行
答案 0 :(得分:2)
只需使用url()
代替path()
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin', admin.site.urls),
url(r'^moraimono/', include('moraimono.urls')),
]
在url
文档的here
答案 1 :(得分:0)
urlpatterns
应该是url()
个实例的列表。 :
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^index/$', index_view, name='main-view'),
url(r'^moraimono/', include('moraimono.urls')),
...
]
url()
在内部定义为:
def url(regex, view, kwargs=None, name=None):
if isinstance(view, (list, tuple)):
# For include(...) processing.
urlconf_module, app_name, namespace = view
return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
elif callable(view):
return RegexURLPattern(regex, view, kwargs, name)
else:
raise TypeError('view must be a callable or a list/tuple in the case of include().')
答案 2 :(得分:0)
使用RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php
RewriteCond %{HTTP_HOST} ^em.example.com/lib/view/map$ [NC]
RewriteRule ^pathurl/(.*)$ /em.example.com/map/$1 [R=301,NC,L]
,您已将其导入,而在django 2.0中,它与url
re_path