簡體   English   中英

當我在 Django 中運行服務器時如何設置默認 url

[英]How to set the default url when i run server in Django

在 Django 中,當我運行服務器時,默認 url 總是出現http://127.0.0.1:8000/blog/

但我想要 justin http://127.0.0.1:8000 url 開始。

如何更改 url 的默認值?

在 urls.py 中,沒有重定向視圖功能。

這是我的應用程序 urls.py

from django.urls import path
from django.views.generic import RedirectView
from . import views

app_name = 'jack'
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
path('', RedirectView.as_view(url='/jack/', permanent=True))
]

這是我的項目 urls.py

from django.contrib import admin
from django.urls import path, include
from django.views.generic import RedirectView

urlpatterns = [
path('jack/', include('jack.urls')),
path('admin/', admin.site.urls),
path('', RedirectView.as_view(url='/jack/', permanent=True))
]

在您的項目urls.py您將 jack 應用程序的路徑設置為使用127.0.0.1:8000/jack

將路徑更改為如下所示: path('', include('jack.urls')),

你可以刪除這個: path('', RedirectView.as_view(url='/jack/', permanent=True))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM