这是来自models.py的课程:
class Person(models.Model):
name = models.CharField(max_length=64)
persnr = models.AutoField(primary_key=True)
Run Code Online (Sandbox Code Playgroud)
这是我的看法:
def show_person(request, persnr):
pers = get_object_or_404(Person, pk=persnr)
context={'pers':pers}
return render(request, 'company/person.html', context)
Run Code Online (Sandbox Code Playgroud)
这是我的网址:
url(r'^show_person/(?P<persnr>\d+)', "company.views.show_person", name='show_person'),
Run Code Online (Sandbox Code Playgroud)
如何使用以下两个网址进入同一视图(show_person):
server/show_person/(persnr)
server/show_person/(name)
Run Code Online (Sandbox Code Playgroud) 我有一个小问题,我暂时找不到解决方案。我有一个脚本,可以在循环中生成大量数字。我循环第一个文件,制作 10 个数字,然后我取第二个文件等等......
一切似乎都有效,但在我的最后一张图中,我得到一个颜色条,然后在第二个循环后得到 2 个颜色条,然后是 3 个等等......这个问题只出现在我的最后一个图中。
你对这种问题有什么想法吗?
这是我的最后一个情节的循环结束:
fig = plt.gcf()
SN_map_final = (S_N_map - mean_SN) / sigma_SN
fig12 = plt.figure(12)
fig_SN_final = plt.imshow(SN_map_final)
cbar = plt.colorbar()
cbar.set_label(r'Signal to Noise (significance $\sigma$)')
plt.xlabel('X (arcmin)')
plt.ylabel('Y (arcmin)')
plt.title('Signal to Noise map')
fig12 = plt.savefig(outname12)
Run Code Online (Sandbox Code Playgroud)
谢谢你,如果你有办法解决这个问题;)
解决方案 :
我补充说:
plt.clf()
Run Code Online (Sandbox Code Playgroud)
在我的循环结束时,它似乎有效
我想创建像下面这样的5*3数组,而不是明确地输入它.
[[1, 6, 11],
[2, 7, 12],
[3, 8, 13],
[4, 9, 14],
[5, 10, 15]]
Run Code Online (Sandbox Code Playgroud)
我用过以下代码.
np.arange(1, 16).T.reshape((5,3))
Run Code Online (Sandbox Code Playgroud)
但它表明
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12],
[13, 14, 15]])
Run Code Online (Sandbox Code Playgroud)
如何按升序排序数字,使其成为第一个数组?
我需要一些建议,以便在我的价值观列表上进行审核。我有一张桌子llx_societe和一些字段,其中一个是code_client。该字段看起来像:
0099
00100
00101
00102
...
00998
00999
001000
Run Code Online (Sandbox Code Playgroud)
我想删除00100和之间的所有值的第一个零00999,以便0100直到0999。
我写了这个命令:
UPDATE `llx_societe`
SET `code_client`= SUBSTR(code_client,1)
WHERE `code_client` BETWEEN '00100' AND '00999';
Run Code Online (Sandbox Code Playgroud)
但是什么也没有,没有任何行进。
你有解释吗?
我想,以改善创造了我生成的PDFxhtml2pdf有一些CSS style在我的Django Project。
我想例如justify a text block,但显然,它不起作用,我不知道为什么。我正在阅读很多关于这个库的文档,我写了一些 CSS 脚本,但仍然没有。
这是我的 HTML 文件:
<html>
<head>
{% load staticfiles %}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" />
<style>
p {text-align: justify;}
</style>
</head>
<font face="Courier New, monospace"
<body>
<logo class="logo">
<img src='/Users/valentinjungbluth/Desktop/Django/Etat_civil/Etat_civil/static/images/logo.png' />
</logo>
<h2 align="center"> <font color="red" size="6"> ACTE DE NAISSANCE <br /> COPIE INTEGRALE </font></align> </h2>
<br></br>
<br></br>
{% block content %}
<h3 align="left"> ACTE DE NAISSANCE N° {{birthcertificate.id}} / …Run Code Online (Sandbox Code Playgroud) 我在我的代码中遇到了这个常见错误:
Exception Type: UnicodeEncodeError
Exception Value:'ascii' codec can't encode character u'\xe9' in position 6: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
为什么?因为我正在处理带有法语口音的名字.
这是我的代码:
if 'rechercheGED' in request.GET:
query_social_number = request.GET.get('q1social')
sort_params = {}
Individu_Recherche.set_if_not_none(sort_params, 'NumeroIdentification__iexact', query_social_number)
query_lastname_list = Individu_Recherche.Recherche_Get(Individu, sort_params)
lastname = query_lastname_list.Nom
firstname = query_lastname_list.Prenom
NIU = query_lastname_list.NumeroIdentification
title = str(lastname + "_" + firstname + "_" + NIU)
Run Code Online (Sandbox Code Playgroud)
问题来自: firstname = query_lastname_list.Prenom
因为在我的情况下,名字是 Jérôme
我尝试了一些东西:
1)在开头插入:
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
Run Code Online (Sandbox Code Playgroud)
2)使用firstname = query_lastname_list.Prenom.encode('utf-8')和firstname = …
我正在学习这个新的语言PHP,以便从这个软件开发模块:Dolibarr
这是我第一次使用PHP而且我没有克服在我的视图中显示查询结果.
我想知道我的脚本是否写错了,因为到现在为止我还不懂.我想显示我的软件中的用户数量.我必须查询我的llx_user表并在我的数组中显示结果.
这是我的代码的一部分:
/*
* View
*/
//Display number of users
$sql = "SELECT COUNT(u.rowid) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$result = $db->query($sql);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
if (! empty($conf->user->enabled))
{
$statUsers = '<tr class="oddeven">';
$statUsers.= '<td><a href="index.php">'.$langs->trans("Number of Users").'</a></td><td align="right">'.round($result).'</td>';
$statUsers.= "</tr>";
}
$total=0;
if ($entity == '0')
{
print $statUsers;
$total=round($result);
}
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
print $total;
print '</td></tr>';
print '</table>';
print '</div></div></div>';
llxFooter(); …Run Code Online (Sandbox Code Playgroud) 我正在使用carousel以显示我的django应用程序中的一些图片。轮播显示图片列表中的图片,我想将第一个设置为active.
这是我的脚本:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
{% for publication in publication_list_carousel %}
<li data-target="#myCarousel" data-slide-to="{{ publication.id }}" class="active"></li>
{% endfor %}
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="" alt="Cover page">
</div>
{% for publication in publication_list_carousel %}
<div class="item">
{% thumbnail publication.cover "200x200" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
<div class="carousel-caption"> …Run Code Online (Sandbox Code Playgroud) 我想将我的代码减少到更好的程度。这就是为什么我试图将 if/else 语句转换为运算符 ?:
我的实际代码如下所示:
if (resultat.CodeAlgo != null)
{
worksheet.Cells[ligne, 7].Value = resultat.CodeAlgo.ToString();
}
else
{
worksheet.Cells[ligne, 7].Value = string.Empty;
}
Run Code Online (Sandbox Code Playgroud)
我尝试转换为:
resultat.CodeAlgo != null
? worksheet.Cells[ligne, 7].Value = resultat.CodeAlgo.ToString()
: worksheet.Cells[ligne, 7].Value = string.Empty;
Run Code Online (Sandbox Code Playgroud)
但它说:
只能使用赋值、调用、自增、自减、new object 语句作为语句。
我第一次使用这个运算符,我不明白为什么我的简化是错误的?
我想get_queryset()与基于类的视图一起使用,但是我没有克服在模板中显示变量的问题。
功能很简单:
class MyClassView(LoginRequiredMixin, ListView) :
template_name = 'my_template.html'
model = Foo
def get_queryset(self) :
foo = Foo.objects.order_by('-id')
bar = foo.filter(Country=64)
return foo, bar
Run Code Online (Sandbox Code Playgroud)
和我的模板:
<table style="width:120%">
<tbody>
<tr>
<th>ID</th>
</tr>
{% for item in foo %}
<tr>
<td>{{ foo.id }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<br></br>
<table style="width:120%">
<tbody>
<tr>
<th>ID</th>
</tr>
{% for item in bar %}
<tr>
<td>{{ bar.id }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我必须使用Context字典吗?
django ×4
python ×4
html ×2
mysql ×2
ascii ×1
c# ×1
carousel ×1
colorbar ×1
css ×1
django-urls ×1
django-views ×1
dolibarr ×1
if-statement ×1
matplotlib ×1
numpy ×1
php ×1
python-2.7 ×1
utf-8 ×1
xhtml2pdf ×1