Django crash: Build a blog

Source: Internet
Author: User

Www.facebuyer.com

1. Create a Django Project

$> Django-admin.py startproject mysite

2. Run the Development Server

$>. \ Manage. py runserver

Browse http: // 127.0.0.1: 8000/

3. Create a blog Application

$>. \ Manage. py Startapp blog

4. Modify mysite/settings. py

Find installed_apps and add: mysite. Blog

5. Design a model

Open mysite/blog/models. py to add

Class blogpost (models. Model ):
Title = models. charfield (max_length = 150)
Body = models. textfield ()
Timestamp = models. datetimefield ()

6. Set the database. SQLite is used here.

# Create a directory: \ mysite \ app_data \

# Edit \ mysite \ Settings. py

Database_engine = 'sqlite3'

Database_name = r 'd: \ projects \ others \ Django. learn01 \ mysite \ data \ Django. db'

# Synchronize Databases

$>. \ Manage. py syncdb

Prompt for User Creation

7. Set the automatic admin Application

# Enable settings. py under installed_apps

'Django. contrib. auth ',
'Django. contrib. admin ',

# Run commands

$>. \ Manage. py syncdb

8. Open URLs. py to add

From Django. contrib import Admin
Admin. autodiscover ()

Urlpatterns = patterns ('',

(R' ^ admin/', include (Admin. Site. URLs )),

)

9. Open mysite/blog/models. py to add

From Django. contrib import Admin

Admin. Site. Register (blogpost)

10. Try Admin

Http: // 127.0.0.1: 8000/admin/

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.