Django-bootstrap Integrated __django

Source: Internet
Author: User
Tags install django pip install django
Bootstrap as a popular front-end framework, has been adopted by many projects, if users accept not to use IE, using bootstrap will greatly reduce our development costs. Here's a simple introduction to Django and Bootstrap integration.


1. Install Django-bootstrap-static

Django-bootstrap-static is installed with PIP, installation steps are as follows

Easy_install pip
pip install django-bootstrap-static

After the installation is successful, a bootstrap directory is added to the Python/site-packages directory
Introduced in 2.settings.py

Installed_apps = (
    ' Django.contrib.auth ',
    ' django.contrib.contenttypes ', '
    django.contrib.sessions ',
    ' django.contrib.sites ',
    ' django.contrib.messages ',
    ' django.contrib.staticfiles ',
    # Uncomment The next line to enable the admin:
    ' django.contrib.admin ',
    # uncomment the next line to enable admin documentation :
    # ' Django.contrib.admindocs ',
    ' order ',
    ' Bootstrap ',
)

Notice to join the bootstrap at the end.
3. Introduction of Base.html
Note that you can find a base.html in the site-packages\bootstrap\templates\bootstrap\ directory, replace it with the base.html that the teacher wrote, and note that the {{Static_url}} in the file is changed to/ static/, as follows

    <link href= "/static/bootstrap/css/bootstrap.css" rel= "stylesheet" >
    <link href= "/static/bootstrap/" Css/bootstrap-responsive.css "rel=" stylesheet ">

4. Use of Bootstrap
Once you have completed the above steps, you can use bootstrap, such as its NAV function:

<div class= "NavBar navbar-inverse navbar-fixed-top" > <div class= "Navbar-inner" > <div class= "Con"
               Tainer-fluid "> <a class=" btn btn-navbar "data-toggle=" collapse "data-target=". Nav-collapse ">
               <span class= "Icon-bar" ></span> <span class= "Icon-bar" ></span> <span class= "Icon-bar" ></span> </a> <a class= "brand" href= "#" >eshop</a&
            Gt <div class= "Nav-collapse collapse" > <p class= "Navbar-text pull-right" > Welcome, <a href= "#" class= "Navbar-link" >{{user.username}}////{{user.email}}</a> <a href= "/A
                dmin/password_change/"> Modify password </a>/<a href="/admin/logout/"> Logoff </a> </p> <ul class= "nav" > <li class= "active" ><a href= "#" >Home< /a></li> <li><a href= "#about" >About</a></li> &LT;LI&GT;&L T;a href= "#contact" >Contact</a></li> </ul> </div><!--/.nav-colla PSE--> </div> </div> </div>


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.