我对 Django 很陌生,只是尝试使用视图的 url 结构基本上是这样的:
新年: (所有这些应用程序文件+模板) 测试 (所有这些网站文件+模板) 管理.py
在新年 urls.py 上
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
关于views.py
from django.shortcuts import render
import datetime
# Create your views here.
def index(request):
now = datetime.datetime.now()
return render(request, 'newyear/index.html', {
"newyear": now.month == 1 and now.day == 1
})
在测试中的 urls.py 上
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('newyear/', include('newyear.urls')),
path('admin/', admin.site.urls),
]
I have rerun the server but still only recognizes /admin, please help thanks
关于测试中的设置
INSTALLED_APPS = [
'newyear',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
您可能需要在新年 urls.py 中设置
app_name
。它应该看起来像这样:
from django.urls import path
from . import views
app_name = "newyear" #set this
urlpatterns = [
path('', views.index, name='index')
]