![](/img/trans.png)
[英]Using the URLconf defined in Django tried these URL patterns in this order:
[英]Using the URLconf defined in name, Django tried these URL patterns, in this order
我有一个 django 项目,在这个项目中我有两个应用程序:main 和 profiles。
所以我将两个迷你应用程序都添加到 settings.py 文件中:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'profiles',
]
我可以运行主应用程序 - 如果我 go 到:
http://127.0.0.1:8000/
它正在运行。
但如果我 go 到:
http://127.0.0.1:8000/profiles
然后我得到这个错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/profiles
Using the URLconf defined in schoolfruitnvwa.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
The current path, profiles, didn’t match any of these.
所以我的问题是:如何解决这个问题?
谢谢
我的 view.py 文件如下所示:
from django.shortcuts import render
from django.views import View
# Create your views here.
class CreateProfileView(View):
def get(self, request):
return render(request, "profiles/create_profile.html")
def post(self, request):
pass
这是我的 urls.py 文件:
from django.urls import path
from . import views
urlpatterns = [
path("", views.CreateProfileView.as_view())
]
您很可能需要在主应用程序的urls.py
文件中添加一个条目:
from django.urls import include, path
urlpatterns = [
# ...
path('profiles/', include('profiles.urls')),
# ...
]
这样,您的个人资料应用程序的urls.py
将被包含在内。 如果您随后在此文件中定义一个条目path('', views.myview)
,整个 url profiles/
将链接到该视图。
教程中的详细信息,我强烈建议从头到尾完成: https://docs.djangoproject.com/en/4.1/intro/tutorial01/#write-your-first-view
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.