下面是我的代碼。在我的 hello_world 專案中有兩個應用程式頁面。一個是主頁,另一個是個人資料頁面。主頁作業正常,但個人資料頁面顯示錯誤。
hello_world urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('home_page.urls',)),
path('profile_page',include('profile_page.urls',))
]
主頁 urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.home,name='home page'),
]
主頁視圖.py
from django.http import HttpResponse
def home(request):
return HttpResponse('home page')
個人資料頁面 urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('profile_page',views.profile,name='profile page'),
]
個人資料頁面瀏覽量.py
from django.http import HttpResponse
def profile(request):
return HttpResponse('profile page')
uj5u.com熱心網友回復:
您需要使用重定向方法并包含視圖名稱空間作為引數..
找到更新后的代碼: from django.http import HttpResponse def profile(request): return redirect('profile page')
不要忘記匯入重定向...
uj5u.com熱心網友回復:
path() 函式的第一個引數,即'route' 引數,必須以正斜杠結尾。
path('profile_page/',include('profile_page.urls',))
請注意第一個引數'profile_page/'末尾的正斜杠。
由于缺少斜杠,您的 URLconf 與預期模式不匹配。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/352957.html
標籤:姜戈 django-apps
