settings.py #设置文件上传路径,图片上传、文件上传都会存放在此目录里MEDIA_URL = ‘/media/‘MEDIA_ROOT = os.path.join(BASE_DIR, ‘media‘)
#PEP8:missing whitespace around operator os前后有空格都不行
TEMPLATES = [ { ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘, ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)] , ‘APP_DIRS‘: True, ‘OPTIONS‘: { ‘context_processors‘: [ ‘django.template.context_processors.debug‘, ‘django.template.context_processors.request‘, ‘django.contrib.auth.context_processors.auth‘, ‘django.contrib.messages.context_processors.messages‘, ‘django.template.context_processors.media‘, ], }, },] urls.py
from django.contrib import adminfrom django.urls import path,include,re_pathfrom django.views.static import servefrom django.conf.urls.static import staticfrom myblog import settingsfrom blog import viewsurlpatterns = [ path(‘admin/‘, admin.site.urls),#管理后台 path(‘‘, views.index, name=‘index‘),#网站首页 path(‘list-<int:lid>.html‘, views.list, name=‘list‘),#列表页 path(‘show-<int:sid>.html‘, views.show, name=‘show‘),#内容页 path(‘tag/<tag>‘, views.tag, name=‘tags‘),#标签列表页 path(‘s/‘, views.search, name=‘search‘),#搜索列表页 path(‘about/‘, views.about, name=‘about‘),#联系我们单页 path(‘ueditor/‘, include(‘DjangoUeditor.urls‘)), re_path(‘^media/(?P<path>.*)$‘, serve, {‘document_root‘: settings.MEDIA_ROOT}),]
原文地址:https://www.cnblogs.com/master-road/p/10355915.html
时间: 2024-10-19 03:51:41