python-django-blog

下载  [Django 1.6.3]可不要

Python 2.7.5 / get-pip.py  / MySQL-python-1.2.5.win32-py2.7

安装1python->直接运行(next)

               2  运行MySQL-python-1.2.5.win32-py2.7

3、get-pip.py(dos)->(当前目录)python get-pip.py

4、 Django 1.6.3(dos) –> pip install Django  

下载编辑器: Sublime text(直接安装就可)

 

 

创建项目流程(配置好环境后)

       1、创建项目:         django-admin.py startproject 项目名称

2、建立子项目:        manage.py startapp 应用名称

3、配置好settings.py:(1)  

3-1配置好url.py (4)

配置好admin.py (2)

配置好models.py (3)

创建数据库(可以手动,也可以dos创建) 数据库名必须和settings匹配

初始化数据库 manage.py syncdb

运行模拟服务器 manage.py runserver

测试: localhost:8000/admin

 

(4) urls.py

 

from django.conf.urls import patterns, include, url

from django.conf import settings

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.contrib import admin

admin.autodiscover()

 

urlpatterns = patterns('',

    # Examples:

    # url(r'^$', 'blogs.views.home', name='home'),

    # url(r'^blog/', include('blog.urls')),

 

    url(r'^admin/', include(admin.site.urls)),

)

if settings.DEBUG:

      urlpatterns += staticfiles_urlpatterns()

 

 

(3) models.py

      from django.db import models

 

# Create your models here.

class Articles(models.Model):

    title = models.CharField(max_length=200)

    description = models.CharField(max_length=255)

    content = models.TextField()

    views_count = models.IntegerField(default=0)

    created_at = models.DateTimeField(auto_now_add=True)

    updated_at = models.DateTimeField(auto_now=True)

 

(2) admin.py

    from django.contrib import admin

from blog3.models import Articles

 

class ArticlesAdmin(admin.ModelAdmin):

         fields = ('title',)

admin.site.register(Articles, ArticlesAdmin)

 

 

(1)   settings.py

#coding:utf-8

"""

Django settings for blog project.

 

For more information on this file, see

https://docs.djangoproject.com/en/1.6/topics/settings/

 

For the full list of settings and their values, see

https://docs.djangoproject.com/en/1.6/ref/settings/

"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

 

 

# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

 

# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = '((0us73r+=%#(4k0sggs*l$f%0n76wq20i-g53uul^5w2xq_d9'

 

# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True

 

TEMPLATE_DEBUG = True

 

ALLOWED_HOSTS = []

 

 

# Application definition

 

ROOT_URLCONF = 'blogs.urls'

 

WSGI_APPLICATION = 'blogs.wsgi.application'

 

# Database

# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

 

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.mysql',

        'NAME': 'blogs',

             'HOST': 'localhost',

             'USER': 'root',

             'PASSWORD':'',

             'PORT': '3306',

    }

}

 

# Internationalization

# https://docs.djangoproject.com/en/1.6/topics/i18n/

 

LANGUAGE_CODE = 'zh-cn'

 

TIME_ZONE = 'UTC'

 

USE_I18N = True

 

USE_L10N = True

 

USE_TZ = True

 

 

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR,'collectstatic/').replace('\\','/')

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR,'data/').replace('\\','/')

MEDIA_URL = '/media/'

AUTHENTICATION_BACKEND = ('django.contrib.auth.backends.ModelBackend',)

TEMPLATE_CONTEXT_PROCESSORS = (

    "django.contrib.auth.context_processors.auth",

    "django.core.context_processors.debug",

    "django.core.context_processors.i18n",

    "django.core.context_processors.media",

    "django.core.context_processors.static",

    "django.core.context_processors.tz",

    "django.core.context_processors.request",

    "django.contrib.messages.context_processors.messages",

 

)

TEMPLATE_LOADERS = (

    'django.template.loaders.filesystem.Loader',

    'django.template.loaders.app_directories.Loader',

)

TEMPLATE_DIRS =(

    os.path.join(BASE_DIR,'template'),

)

STATICFILES_DIRS = (

    os.path.join(BASE_DIR, "statics"),

 

)

 

INSTALLED_APPS = (

    'django.contrib.auth',

    'django.contrib.admin',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'django.contrib.webdesign',

    'blog3',

)

 

MIDDLEWARE_CLASSES =(

    'django.middleware.common.CommonMiddleware',

    'django.contrib.sessions.middleware.SessionMiddleware',

    #'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',

    'django.contrib.messages.middleware.MessageMiddleware',

    'django.middleware.clickjacking.XFrameOptionsMiddleware',

 )

 

FILE_UPLOAD_HANDLERS=(

    "django.core.files.uploadhandler.MemoryFileUploadHandler",

    "django.core.files.uploadhandler.TemporaryFileUploadHandler",

)

 

     

       


你可能感兴趣的:(python-django-blog)