首页 > 技术文章 > 新闻网站项目django--一些必要的配置

xyxpython 2017-04-11 22:39 原文

settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'zhidaily',                                  #记得在这里添加你的app
]
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',
            ],
        },
    },
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'   #静态文件目录地址
MEDIA_URL = '/upload/'  #上传文件目录地址
MEDIA_ROOT = os.path.join(BASE_DIR, 'upload').replace("//", "/") #上传文件的绝对路径

STATICFILES_DIRS = (os.path.join('static'),) #静态文件的绝对路径

admin.py:

from django.contrib import admin
from newswebsite.models import *

# Register your models here.记得在下面添加你要进行后台管理的模型
admin.site.register(Article)
admin.site.register(Category)
admin.site.register(Best)
admin.site.register(UserProfile)
admin.site.register(Comment)

urls.py:

from django.conf.urls.static import static
from django.conf import settings

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

#配置静态文件和上传文件的代码,目前我还不是很明白这几句的意思。

 

推荐阅读