BootStrap扔進(jìn)Django里的方法詳解

字號(hào):


    這篇文章主要介紹了BootStrap扔進(jìn)Django里的方法,小編認(rèn)為本文介紹的不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧
    因?yàn)閐jango的版本差異化比較大,所以以下配置僅供學(xué)習(xí)參考。
    D:\www\mysite>python --version
    Python 2.7.5
    >>> print django.__version__
    1.9.4
    本記錄不作細(xì)說(shuō),主要配置過(guò)程如下:
    1.settings.py最后一段,關(guān)于靜態(tài)文件的配置
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.9/howto/static-files/
    SITE_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
    STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
    STATIC_URL = '/static/'
    STATICFILES_DIRS = (
    ("css", os.path.join(STATIC_ROOT, 'css')),
    ("js", os.path.join(STATIC_ROOT, 'js')),
    ("images", os.path.join(STATIC_ROOT, 'images')),
    ("bower_components", os.path.join(STATIC_ROOT, 'bower_components')),
    )
    2.urls.py 關(guān)于路由的配置
    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.index),
    url(r'^home/', views.home),
    ]
    3.views.py 視圖設(shè)計(jì),簡(jiǎn)單得不能再簡(jiǎn)單的那種。
    def home(request):
    return render_to_response('home/login.html')
    4.模板調(diào)用 home/login.html 頁(yè)面對(duì)于靜態(tài)文件css, js,以及圖片等調(diào)用。
    <!-- Bootstrap Core CSS -->
    <link href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="/static/css/sb-admin-2.css" rel="stylesheet">
    <img src="/static/images/xjlxprocess.png" />
    5.最后,我的目錄結(jié)構(gòu),就如網(wǎng)上其它文章所描述的那樣。
    website
    ---------static
    ---------|-----css
    ---------|-----js
    ---------|-----images
    ---------|-----bower_components
    ---------templates
    ---------|-----home
    ---------|-----------login.html
    ---------|-----admin
    ---------website
    6.站點(diǎn)打開(kāi)如下:
    名單
    以上內(nèi)容是小編給大家介紹的BootStrap扔進(jìn)Django里的方法詳解,希望對(duì)大家有所幫助