欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

django-blog(一) 博客分类: django

程序员文章站 2024-03-19 11:17:10
...
 706  mkdir blogenv
  707  cd blogenv/
  708  pip install virtualenv
  709  virtualenv blog_env
  710  ls
  711  cd blog_env/
  725  source bin/activate
  726  pip install django
  727  django-admin startproject blogproject
  728  cd blogproject/
  730  python manage.py startapp blog
  736  pip install pillow
  737  vim blogproject/settings.py
mkdir templetes static
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog'
]
 
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ os.path.join(BASE_DIR,'templates')], #templates seting
        '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_URL = '/static/'
STATICFILES_DIRS=( os.path.join(BASE_DIR,'static'),)
 
 
vim blog/views.py
def index(request):
    return render(request,'index.html')
vim blogproject/url.py
from django.conf.urls import url
from django.contrib import admin
from blog.views import *
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$',index,name='index'),
]

模版设置

vim index.html

 

{% load staticfiles %}

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>{{ SITE_NAME }}</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<link href='{% static "css/base.css" %}' rel="stylesheet">

<link href='{% static "css/index.css" %}' rel="stylesheet">

<script type="text/javascript" src='{% static "js/jquery.min.js" %}'></script>

<script type="text/javascript" src='{% static "js/sliders.js" %}'></script>