我试图设置我的django主页,链接到我网站的根:即。
http://127.0.0.1:8000/index/
但是,我总是在django搜索myapp作为主页时出错:
http://127.0.0.1:8000/myapp/
. 我只想登陆一个网址上有“index”的主页,而不是“myapp/”
错误如下:
Using the URLconf defined in Main.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
[name='myapp_index']
publications/ [name='publications']
^static\/(?P<path>.*)$
The current path, myapp/, didn't match any of these.
VIEW
def index(request):
return render(request, 'index.html')
主/网址
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
MyAPP/URL
from django.urls import path
from logbook import views
urlpatterns = [
path('', views.index, name='index'),
path('', views.myapp_index, name='myapp_index'),
path('publications/', views.publications, name='publications'),
]
现在,如果我改变路径
主/ ur.sPy
到
path('myapp/', include('myapp.urls')),
我登陆了相应的主页,除了,我希望在url中列出“index/”而不是“myapp/”。
我可能遗漏了一些很简单的东西。这是我认为是我的MWE,很高兴再加上。