Reference: Django Web Development Guide. PDF May 2009 1th Edition
In the following, all mentioned Jackerb is my own project name, so I need to set according to my own.
Already have admin backstage management, then, now increase on the blog application, to achieve the function of writing their own blog.
Create an app Blog
Use the command django-admin.py Startapp blog, the book said with Python manage.py Startapp blog, in fact, this is the same, but here need to mention a thing, The location of this blog is different for both high and low versions of Django. such as the low version of the Django manage.py file and the settings.py file are in the same directory, but the higher version of the manage.py in the top level of the directory, where is not the problem, the key is that you have to understand in the import these applications, this format, if you are using the high version of the DJ Ango, according to the book execution, the generated blog is and manage.py jackerb these in the same level directory, so when referring to the use of import Jackerb. But I was in the creation of the blog, not in the directory where the manage.py file, I was in the Jackerb directory to execute the django-admin.py Startapp blog, so I use the blog, to
Import Jackerb.blog, that's a little different.
Therefore, I first enter the Jackerb directory and then execute django-admin.py Startapp blog
Then see the file structure under the blog directory is these:
I don't mention what these things are all about, because they're all in the book, and I'm just documenting my own django+sae.
2. Modify jackerb/settings.py file to add blog
Find Installed_apps, add ' jackerb.blog ' at the end
3. Modify blog/models.py, Add blog class
From django.db import Models
From Django.contrib Import admin
Class Blog (models. Model):
title = models. Charfield (max_length=200)
Category = Models. Charfield (max_length=200)
BODY = models. TextField ()
Timestamp = models. Datetimefield ()
Admin.site.register (Blog, Blogadmin)
Now add and commit all the added files and the modified files with SVN add and svn commit.
I have an error above, which is the model in the image parameter. Model, in fact, is models. Model.
4. Now that the new blog application has been added, you need to synchronize the database
As we mentioned earlier, we used a monkey module in settings.py, and we need to remove this comment when we need to synchronize the database, so I'm going to remove this comment locally without committing it. This time execution, Python manage.py syncdb.
A blog-related table will be generated. Don't forget to annotate the monkey after the build.
5. Open http://jackerb.sinaapp.com/admin/
At this time you can see that there is already a blog. At this point we can, click Add Add, to add our own blog. Actually now finished can be used, as long as they do not feel trouble. And now it's time to write our own blog here.
At this time to finish writing, found that the name of the display is a blog object, does not show the name of the blog we defined, and now to set up a bit.
Modify blog/models.py
From django.db import Models
From Django.contrib Import admin
Class Blog (models. Model):
title = models. Charfield (max_length=200)
Category = Models. Charfield (max_length=200)
BODY = models. TextField ()
Timestamp = models. Datetimefield ()
Class Blogadmin (admin. Modeladmin):
List_display = (' title ', ' Category ', ' timestamp ')
Admin.site.register (Blog, Blogadmin)
Submit the changes to the SAE, at this time to refresh the previous page, you can see the blog according to the title, categories, times to show.
This is the section, and then I'll get my blog content on my own SAE. Now we can edit their own blog, but to let others see what to do, this page is not for others to see, the next section on the basis of that information, continue to operate.
Django+sae Personal Blog Four