Django+python+eclipse Quickly build blog Blogs

Source: Internet
Author: User
Tags sqlite database create blog

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.





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.