创建应用和index页面,还有配置静态文件目录和静态文件目录集

This commit is contained in:
mxjdi 2025-04-04 23:08:44 +08:00
parent f27675b1b2
commit fa36da700a
11 changed files with 39 additions and 6 deletions

View File

@ -15,7 +15,6 @@ from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
@ -27,7 +26,6 @@ DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
@ -37,6 +35,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
"helloWorld.apps.HelloworldConfig"
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -69,7 +68,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'Django5.wsgi.application' WSGI_APPLICATION = 'Django5.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases # https://docs.djangoproject.com/en/5.2/ref/settings/#databases
@ -80,7 +78,6 @@ DATABASES = {
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
@ -99,7 +96,6 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/ # https://docs.djangoproject.com/en/5.2/topics/i18n/
@ -111,12 +107,14 @@ USE_I18N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/ # https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'static/'
# 设置静态资源文件集合
# STATICFILES_DIRS = [BASE_DIR / 'static', BASE_DIR / 'helloworld/images']
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

View File

@ -17,6 +17,9 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
import helloWorld.views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('index/', helloWorld.views.index),
] ]

0
helloWorld/__init__.py Normal file
View File

3
helloWorld/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
helloWorld/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class HelloworldConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'helloWorld'

View File

3
helloWorld/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

BIN
helloWorld/static/logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

3
helloWorld/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
helloWorld/views.py Normal file
View File

@ -0,0 +1,6 @@
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'index.html')

11
templates/index.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>Django5大爷你好</p>
<a href="http://python222.com/post/7" target="_blank">Python学习路线图</a>
</body>
</html>