Python 1 day training 102 ---- create a simple blog (below), python102 ----

Source: Internet
Author: User
Tags django website

Python 1 day training 102 ---- create a simple blog (below), python102 ----

Continue to change the blog and continue to change the blog in the previous article.



My mother tongue is not swollen in English. I have a lot of English on my blog!

The change is simple.

You can make a quick change to see if the Django management tool is translated into the language you want. Only in settings. add 'django. middleware. locale. localeMiddleware is in the MIDDLEWARE_CLASSES settings, and make sure it is in 'django. contrib. sessions. middleware. sessionMiddleware.


Create a template for the foreground part of the blog in the path C: \ mysite \ templatescreate the index.html file. The content is as follows:
<Html> Create a view and modify C: \ mysite \ blog \ views. py
#coding:utf-8from django.template import loader,Contextfrom django.http import HttpResqonsefrom mysite.blog.models import BlogPostdef archive(request):    posts=BlogPost.objects.all()    t=loader.get_template("index.html")    c=Context({"posts":posts})    return HttpResponse(t.render(c))
Create URLconf and modify c: \ mysite \ urls. py
from django.conf.urls import patterns, include, urlfrom django.contrib import adminurlpatterns = patterns('',    # Examples:    # url(r'^$', 'mysite.views.home', name='home'),    #url(r'^blog/', include('blog.urls')),    url(r'^admin/', include(admin.site.urls)),    url(r"^blog/",'blog.views.archive'),)

Now you have a simple front-end interface.

Although this homepage is very tricky, there are at least the most basic functions of the blog homepage.



Above.



The main knowledge point of a simple blog is Django website management (Django admin ). The following is an introduction to Django admin:
Django admin is the site management tool that comes with django. Our website must not only have common display pages, but also have a good background management interface. For example, in the background of a blog, you can write your own blog and publish it. In a forum, you can manage various permissions, review posts, and personnel access. The admin page is particularly important for a website based on content.

However, there is a problem in the Management Interface: It is too cumbersome to create it. Webpage development is interesting when you develop public functions, but the management interface is usually the same. You must authenticate users, display and manage tables, and verify the validity of input. This is tedious and repetitive. You can use Django admin to reduce these problems. The basic style and management methods of django admin are the same. django also provides a variety of interfaces for developers to DIY.
Of course, you can also write the background management that meets the requirements of this website without using django admin. openstack horizon is an open-source management backend developed based on django.


Source Code address: http://download.csdn.net/detail/a359680405/8401353




Last Lecture: Python practice 101 a day ---- creating a simple blog (on)

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.