zoukankan      html  css  js  c++  java
  • Django 静态资源路径问题(一)

    2013.10.17日(初学,手写) 系统 ubuntu  python2.7.4   Django1.5.4

    1.

    /hone/yuluhuang/python/

    2.创建项目

    django-admin.py startprojects  one   ==>   /hone/yuluhuang/python/one/one[产生两个one文件夹]

    3.进入

    cd one/one

    4.创建应用

    django-admin.py startapp blog

    5.进入blog文件夹 在blog文件夹中创建templates文件夹

    cd blog

    mkdir templates

        在里面新建index.html

      ...

       <tr><td width="43"><img src="/templates/xxx/xxx.png" alt="" width="43" height="72" /></td></tr>

      ... 

    6.括号内为此文件下的文件

    /hone/yuluhuang/python/one(manage.py)/one(setting.py,urls.py..)/blog(models.py,views.py)/templates

    7.打开setting.py 修改如下

    vim setting.py

    import os

    ...

    STATIC_URL = '/templates/'

    # Additional locations of static files
    STATICFILES_DIRS = (
    os.path.join(os.path.dirname(__file__), './blog/templates/').replace('\','/'),

    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    )

    7.1

    vim urls.py

             url(r'^index/$','one.blog.views.login'),

    7.2

    vim views.py

    from django.http import HttpResponse
    from django.shortcuts import render_to_response

    def index(req):
    return render_to_response('index.html',{})

    8.调用如下

    <tr>
    <td width="43"><img src="/templates/xxx/xxx.png" alt="" width="43" height="72" /></td>
    </tr>

  • 相关阅读:
    hadoop 异常及处理总结-02(小马哥精品)
    Linux环境变量(小马哥推荐)
    Apache Tomcat 8.5 安全配置与高并发优化
    深入理解分布式系统中的缓存架构(上)
    Redis的n种妙用,不仅仅是缓存
    springBoot整合ecache缓存
    Spark Streaming实时处理应用
    Spark 实践
    spark性能调优
    Spark调优
  • 原文地址:https://www.cnblogs.com/yuluhuang/p/3375444.html
Copyright © 2011-2022 走看看