1. New Django Project
Select SQLite Database
2. Create blog Module app
3. Test the new module is normal
4. Edit Code
4.1 Modification blog.models.py
From django.db import models to
django.contrib import Admin
# Create your models here.
Class blogpost (models. Model):
title = models. Charfield (max_length=150) Body
= models. TextField ()
timestamp = models. Datetimefield ()
class blogpostadmin (admin. Modeladmin):
list_display = (' title ', ' Body ', ' timestamp ')
admin.site.register (blogpost,blogpostadmin)
4.2 Modification blog.views.py
# Create your views here.
From django.template import Loader,context to
django.http import HttpResponse from
blog.models Import Blogpost
def archive (Request):
posts = BlogPost.objects.all ()
t = loader.get_template (' archive.html '
C = Context ({' Posts ':p OSTs}) return
HttpResponse (T.render (c))
4.3 Modification mysite.setting.py
Installed_apps = (
' Django.contrib.auth ',
' django.contrib.contenttypes ', '
django.contrib.sessions ',
' django.contrib.sites ',
' django.contrib.messages ',
' django.contrib.staticfiles ',
' blog ',
# Uncomment the "next line" to enable the admin:
' django.contrib.admin ',
# uncomment the next line to enable admin D Ocumentation:
# ' Django.contrib.admindocs ',
)
4.4 Modification urls.py
From Django.conf.urls import patterns, include, url
# uncomment "next two lines to enable" admin: from
Djang O.contrib Import admin
admin.autodiscover ()
from blog.views import *
urlpatterns = Patterns (',
# Examples:
# URL (r ' ^$ ', ' mysite.views.home ', name= ' home '),
# URL (r ' ^mysite/', include (' Mysite.foo.urls ')),
# Uncomment the Admin/doc line below to enable admin documentation:
# URL (r ' ^admin/doc/', include (' Django.contri B.admindocs.urls '),
# Uncomment the next line to enable the admin:
URL (r ' ^admin/', include (Admin.site.urls)) ,
URL (r ' ^blog/$ ', archive),
)
5. Create a Style page template
Note: Please add the Templates folder under the module blog
5.1 Editor Archive.html
{% extends ' base.html '%}
{% block content%}
{% for post in posts%}
5.2 Editor Base.html
6. Synchronizing Databases
Set up your account and password, for the login blog management backstage preparation.
7. Successful Operation
Login interface, login account is the initialization of the database settings, password is also set at that time.