2017-09-18 54 views
1

我有mouvements列表的索引页在数据表上,每行有按钮,允许用户按“编辑”去一个新的页面,在那里他可以查看破坏的细节。Django的路径静态文件改变取决于页

在索引页上的基本细节解放运动网页一切正常工作,静态文件加载路径为/ gestion_mouvements /静态/ ...

但是当我使用“(?P [0-9] +)/ $“在我的网页url中能够获得URL中的mouvement ID,所加载的页面将静态路径更改为gestion_mouvements/mouvementDetails/static/...例如,并且无法加载静态文件,因为路径应该是gestion_mouvements /静态/ ...

我检查和settings.py中尝试了很多不同的静态设置,但没有什么工作,到目前为止,任何人有我如何可以改变这种想法?

这是从应用程序我urls.py

from django.conf.urls import url, patterns 
from .views import * 

urlpatterns = patterns('Gestion_Mouvement.views', 
    url(r'^tableau/(?P<idMI>\d+)$','tableau', name = 'tableau'), 
    url(r'^$', index), 
    url(r'^tableau',tableau, name = 'tableau'), 
    url(r'^mouvementDetails/(?P<pk>[0-9]+)/$', 'mouvementDetails', name = 'mouvementDetails'), 
    url(r'^index', index, name = 'index'), 
    url(r'^refresh_index','refresh_index', name = 'refresh_index'), 
    url(r'^finalisation','finalisation', name = 'finalisation'), 
    url(r'^creation','creation', name = 'creation'), 
    url(r'^historiques','histos', name = 'histos'), 
    url(r'^histo-pt0','histosPT0', name = 'histo-pt0'), 
    url(r'^histo-entrants','histosEntrants', name = 'histo-entrants'), 
    url(r'^histo-sortants','histosSortants', name = 'histo-sortants'), 
) 

我的index.html

{% load static %} 
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Page</title> 
<meta name="generator" content="WYSIWYG Web Builder 12 - http://www.wysiwygwebbuilder.com"> 
<link href="../static\css/Gestion_Mouvements.css" rel="stylesheet"> 
<link href="../static\css/index.css" rel="stylesheet"> 
<link href="{% static 'css/jquery-ui.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/jquery.dataTables.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/bootstrap.min.css" rel="stylesheet' %}" media="all"> 
<link href="{% static 'css//bootstrap-datetimepicker.min.css' %}" media="all" rel="stylesheet"> 
<script src="{% static 'js/jquery-1.12.4.min.js' %}"></script> 
<script src="{% static 'js/jquery.dataTables.min.js' %}"></script> 
<script src="{% static 'js/jquery-ui.min.js' %}"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
$('#indexTab').dataTable({ 
    "bLengthChange": false, 
    "lengthMenu": [ [-1], ["All"] ] 
}); 
$('.editbtn').click(function(){ 
     var $row = $(this).closest("tr"); // Find the row 
     var $text = $row.find(".idMark").text(); // Find the text 
     alert($text); 
    }); 
$('.deletebtn').click(function(){ 
     var $row = $(this).closest("tr"); // Find the row 
     var $text = $row.find(".idMark").text(); // Find the text 
     alert($text); 
    }); 
}); 
</script> 
</head> 
<body> 
<div id="wb_Shape1" style="position:absolute;left:4px;top:5px;width:1300px;height:100px;z-index:0;"> 
<img src="../static\images/img0003.png" id="Shape1" alt="" style="width:1300px;height:100px;"></div> 
<div id="Html1" style="position:absolute;left:4px;top:107px;width:1300px;height:400px;z-index:1"> 
<table id="indexTab" class="display" width="100%" cellspacing="0"> 
      <thead> 
      <tr> 
       <th>ID</th> 
       <th>Date et heure création</th> 
       <th>Véhicule</th> 
       <th>Pesée 1</th> 
       <th>Type mouvement</th> 
       <th>Sous type</th> 
       <th>Code espèce</th> 
       <th>Libellé espèce</th> 
       <th>Edit/Delete</th> 
      </tr> 
     </thead> 
     <tbody>  
      {% for mouvement in mouvements %} 
      <tr name="mvtRow{{mouvement.Id}}"> 
      <th class="idMark">{{mouvement.Id}}</span></th> 
      <th class="ce3l7">{{mouvement.DateHeureCreat}}</span></th> 
      <th class="ce3l8">{{mouvement.Immat_Transporteur}}</span></th> 
      <th class="ce3l9">{{mouvement.Poids_Charge}}</span></th> 
      <th class="ce3l2">{{mouvement.Type_Mouvement}}</span></th> 
      <th class="ce3l8">{{mouvement.Sous_Domaine}}</span></th> 
      <th class="ce3l9">{{mouvement.Espece}}</span></th> 
      <th class="ce312">{{mouvement.Libelle}}</span></th> 
      <th><a href="/gestion_mouvement/mouvementDetails/{{mouvement.Id}}"><button type="button" class="editbtn">Edit</button> <a href="/gestion_mouvement/tableau"><button class="deletebtn">Delete</button></a></th> 
      </tr> 
      {% endfor %} 
     </tbody> 
</table></div> 
<input type="text" id="Editbox1" style="position:absolute;left:15px;top:17px;width:900px;height:30px;line-height:30px;z-index:2;" name="ebFluxState" value="{{listOPT.0}}" readonly spellcheck="false"> 
<input type="submit" id="Button1" name="btn_PeseeSilo" value="Pesée Silo" style="position:absolute;left:936px;top:17px;width:96px;height:40px;z-index:3;"> 
<input type="submit" id="Button2" name="btn_createManual" value="Création Manuelle" style="position:absolute;left:1037px;top:17px;width:119px;height:40px;z-index:4;"> 
<input type="submit" id="Button3" name="btn_refresh" value="Rafraichissement" style="position:absolute;left:1174px;top:17px;width:119px;height:40px;z-index:5;"> 
</body> 
</html> 

和我的settings.py STATIC选项:

#STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static').replace('\\', '/') 
# URL prefix for static files. 
# Example: "http://media.lawrence.com/static/" 
PROJECT_DIR = os.path.dirname(__file__) 
STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, "static") 

STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR,'static'), 
) 

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__),'../templates'), 
) 

到JS的联系/ css文件在其他页面中完全相同,它们的调用方式完全相同,但仍然是/ mouvementDetails/get添加到每个路径

回答

0

其他的事情都是完美的。您需要更改HTML文件的片段,像这样:

{% load static %} 
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Page</title> 
<meta name="generator" content="WYSIWYG Web Builder 12 - http://www.wysiwygwebbuilder.com"> 
<link href="../static\css/Gestion_Mouvements.css" rel="stylesheet"> 
<link href="../static\css/index.css" rel="stylesheet"> 
<link href="{% static 'css/jquery-ui.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/jquery.dataTables.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/bootstrap.min.css" rel="stylesheet' %}" media="all"> 
<link href="{% static 'css//bootstrap-datetimepicker.min.css' %}" media="all" rel="stylesheet"> 
<script src="{% static 'js/jquery-1.12.4.min.js' %}"></script> 
<script src="{% static 'js/jquery.dataTables.min.js' %}"></script> 
<script src="{% static 'js/jquery-ui.min.js' %}"></script> 

要:

{% load static %} 
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Page</title> 
<meta name="generator" content="WYSIWYG Web Builder 12 - http://www.wysiwygwebbuilder.com"> 
<link href="{% static 'css/Gestion_Mouvements.css' %}" rel="stylesheet"> 
<link href="{% static 'css/index.css' %}" rel="stylesheet"> 
<link href="{% static 'css/jquery-ui.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/jquery.dataTables.min.css' %}" media="all" rel="stylesheet"> 
<link href="{% static 'css/bootstrap.min.css" rel="stylesheet' %}" media="all"> 
<link href="{% static 'css//bootstrap-datetimepicker.min.css' %}" media="all" rel="stylesheet"> 
<script src="{% static 'js/jquery-1.12.4.min.js' %}"></script> 
<script src="{% static 'js/jquery.dataTables.min.js' %}"></script> 
<script src="{% static 'js/jquery-ui.min.js' %}"></script> 

由于../static搜索基于静态文件夹的相对路径上的所有可能的组合和项目/应用程序。

+0

我明白这个问题,但是这两个线通过所见即所得的产生,我可以重新把它们写在食,但我的问题是不是索引页,它是在mouvementDetails/[ID],但我有AU汽车同样的问题生成的行错过了django格式。 –

+0

@Girardclément在** mouvementDetails/[ID] ** url中,哪个模板正在呈现。可能有一些问题。像** {%load static%} **可能没有在那里定义,或者这个文件没有在那里扩展。 –

+0

@Girardclément请显示url ** mouvementDetails/[ID] **的视图和模板代码。 –

0

编辑:好了,现在你所提供的相关信息,这个问题是清楚的,看评论。

一些更多的信息例如您在settings.py中的静态设置将非常有帮助。但是,它可能归结为这些事情:

settings.py,一定要设置你的STATIC_URL,你的情况给/static/

# settings.py 
STATIC_URL = '/static/' 

然后,在你的模板:

# your_template.html 
{% load static %} 
<img src="{% static "my_app/example.jpg" %}" alt="My image"/> 
+0

我确实有这些设置,他们对我的所有网页完美,execpt的一个地方,我使用“(?P [0-9] +)/ $” ...... –

+0

不,你不知道。你有两个相对路径“../ static”,而不是使用“{%static”。有问题。 – olieidel