Django Quick Build Blog Section Sixth

Source: Internet
Author: User
Tags button type comments min
in the last section we used a template to get the first Hello World, this class, we show the real data in the database with the detail page of a single article

I. Template download here is the template download refers to the download JS and CSS files, a website want to become beautiful, become a little better to watch, here we use is bootstrap, is a set of Facebook template. Suitable for mobile phone, tablet, mobile side. I also learned this because of learning this framework, but according to the company's front-end small brother said that it is now obsolete, there are a lot of vue,angular,react framework, but we now use it or can make sense.
The following is the template use steps:

1. Https://github.com/zmrenwu/django-blog-tutorial-templates (with the dream eldest brother, this set of learning series is also based on this to make a deeper summary)
2. After downloading, we create a new static folder under the blog/, and then create a new blog folder under Static, so we write the blog according to the function of static will have other functions, or comments function, etc. Work experience will let you understand why, this time we put Css,js folder to Static/blog, the template index.html replace the index.html we wrote earlier, when we start the server will see:

This seems to be JS and CSS does not play a role, we need to index.html in the head tag to re-modify the

 

And here's the:

<!--Mobile menu--
<div class= "Overlay overlay-hugeinc" >
    <button type= "button" class= " Overlay-close "><span class=" Ion-ios-close-empty "></span></button>
    <nav>
        < ul>
            <li><a href= "index.html" > Home </a></li>
            <li><a href= " full-width.html "> Blog </a></li>
            <li><a href=" about.html "> About </a></li>
            <li><a href= "contact.html" > Contact </a></li>
        </ul>
    </nav>
</ div>

<script src= "{% static ' blog/js/script.js '%}" ></script>

</body>
</ Html>

description : Mainly introduced with template code, added {% Static ' blog and%}
Here's <link rel= "stylesheet" href= "{% static ' blog/css/pace.css '%}" > code run in the browser is replaced by:
<link rel= "stylesheet" href= "/static/blog/css/pace.css" >

Let's run it again:
We index.html the data, because there are now multiple article tags, we just need one here, and then write the code:
Templates/blog/index.html

{% for post in post_list%}
  <article class= "Post post-{{post.pk}" >
    ...
  </article>
{% empty%}
  <div class= "No-post" > Articles that have not been released for the time being. </div>
{% endfor%}

Here is the post_list from the blog/views.py index method post_list, template code with a for loop out each post article,
We'll fill in the contents of the Article tab:

{% for post in post_list%} <article class= "Post post-{{Post.pk}}" >  

Once again, the browser displays: Articles that have not been published for the time being

Well, we should create the admin account from the background, to add the article to the operation.

Two. admin background users create and publish articles using the command line: Python manage.py createsuperuser

Here we can temporarily do not fill in the email address, when filling in the password is not to see what you fill out we created a good account, we now need to register in the background we create a few models
Django Quick Build Blog Section III
Here it says, write the above code under blog/admin.py:

From django.contrib import admin from
. Models import Post,category,tag

# Register your models here.

#希望能看到文章的更多信息, not just the article
class postadmin (admin. Modeladmin):
    list_display = [' title ', ' Category ', ' created_time ', ' modified_time ', ' author ']

# Register the newly registered postadmin in
admin.site.register (post,postadmin)
admin.site.register (Category)
Admin.site.register (TAG)

Here a class is written in order to see in the background of post (article) specific information, title, tags, time, etc

Now we are running on the server, input: http://127.0.0.1:8000/admin/

This time

After you have entered:

Let's try a few new articles:

Here, we are refreshing the server, there will be the article we just wrote the title of the author or something

Ending ...

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.