社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

django 2.0:主页/索引的url路径

Nicolas Smoll • 7 年前 • 1882 次点击  

我试图设置我的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,很高兴再加上。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43537
文章 [ 5 ]  |  最新文章 7 年前