【发布时间】:2018-02-26 18:49:43
【问题描述】:
我有一个索引页面,其中包含数据表中的运动列表,每一行都有按钮,允许用户按“编辑”进入新页面,在那里他可以查看运动的详细信息。
在索引页面和基本细节移动页面上一切正常,静态文件加载路径为 /gestion_mouvements/static/...
但是当我在我的页面 url 中使用 "(?P[0-9]+)/$" 来获取 url 中的 mouvement ID 时,加载的页面将静态路径更改为 gestion_mouvements/mouvementDetails/static/ ...例如并且无法加载静态文件,因为路径应该是 gestion_mouvements/static/...
我在 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/ 仍会添加到每个路径中
【问题讨论】:
标签: django python-2.7 django-urls