Django personal simple Blog development-build project structure, django simple Blog Development

Source: Internet
Author: User

Django personal simple Blog development-build project structure, django simple Blog Development

The first step before development is to construct the entire project structure. This is like a painting. The first step is to depict the outline. With the outline, the rest is to fill in the details slowly. Project Structure planning is as follows:

All of the following operations are completed in windows.

 

1. Create a project

Enter the directory where the project is to be stored, and enter the following command in the command line:

# Django-admin.py In Your python installation directory Lib \ site-packages \ django \ bin directory python G: \ python \ Python \ Python2.7Install \ Lib \ site-packages \ django \ bin \ django-admin.py startproject fengzhengBlog

The following directory structure is generated:

FengzhengBlog

|__ FengzhengBlog

|__ Init. py # This file indicates that this directory is a python package that can be empty.

|__ Settings. py # global configuration file

|__ Urls. py # route File

|__ Wsgi. py # use the web Server Gateway Interface to start django

|__ Manage. py # You can use python manage. py runserver to start a website (used only during development)

2. create a blogapp. In django, a project can have multiple apps. Each app can be a relatively independent function module. In this example, blogapp is the blog management function module. Responsible for the unified management of Blog system articles and categories.

Go to the fengzhengBlog/fengzhengBlog directory and execute the following command in the Command window:

python ../manage.py startapp blogapp

The structure of the generated app is as follows:

FengzhengBlog

|__ Blogapp

|__ Migrations # After modifying the Model, you can reconstruct the table structure without affecting existing data.

|__ Init. py # This file indicates that this directory is a python package that can be empty.

|__ Admin. py # used to register and set the background management function of the Model

|__ Models. py # model definition file

|__ Test. py # unit test file

|__ Views. py # View

3. Add static file directories js, images, and css, and configure the routing of static directories in urls. py. The URL. py configuration is as follows:

(R' ^ css /(? P <path>. *) $ ', 'django. views. static. serve ', {'document _ root': OS. path. dirname (_ file _) + '/css'}), (R' ^ js /(? P <path>. *) $ ', 'django. views. static. serve ', {'document _ root': OS. path. dirname (_ file _) + '/js'}), (R' ^ images /(? P <path>. *) $ ', 'django. views. static. serve ', {'document _ root': OS. path. dirname (_ file _) + '/images'} # the absolute path can also be written here ),

4. Create a ueEditor directory and integrate Baidu uEditor. For details about the integration process, see integrate Baidu Rich Text Editor uEditor with Django.

Now, the project structure Planning is complete. Next, create a simple template, add some simple html, js, images, and so on, and check whether the project is running properly.

Create a new HTML file named test.html in the templatedirectory. The content is as follows:

<!DOCTYPE html>

In the imagesdirectory, upload the png_favicon.png image.

Add the bootstrap.min.css file to the CSS directory.

Add route ing in the urls. py file:

url(r'^test$','fengzhengBlog.views.test'),

Define the view processing method in views. py:

#-*-Coding: UTF-8-*-from django. shortcuts import render_to_responsedef test (request): return render_to_response ("test.html", {"btnvalue": "I am a dynamic TAG content, clicke me "})

Run the following command:

python manage.py runserver 1989

Then, enter http: // 127.0.0.1: 1989/test in the browser, open the developer tool, and check that the images, style files, and script files have been loaded successfully:


The python-django framework creates a simple blog. When a post is displayed, the comment box is displayed. The user inputs the submitted verification Article and the comment. The user prompts whether to give a comment to himself. The comment is saved and the prompt is successful.
What is the rapid development of django/python reflected in? How fast is it? Django complies with the mvc pattern. In django, it is called mtv, the model template view. django's philosophy is simple and concise. Coupling. I have written a blog to understand that the general view of django greatly reduces the amount of code. django built-in components are easier to use than comments. You must write code again. django is open-source, multi-country, and multi-language. You should be easy to implement. Look at django book. This is free introduction to django official documentation. Good understanding, there should be something you want.

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.