- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我知道,我重复一遍,我是编程世界的新手...但我更喜欢这样说,即使我认为从我的问题中显而易见...:)
这是我的模板:
Fims.html:
{% extends "Base.html" %}
{% block titolo %}Films{% endblock %}
{% block personalizzazione %}
<style media="screen" rel="stylesheet" type="text/css">
#Films {color:#FF0066; }
</style>
{% endblock %}
{% block testata %}
<div class="grid_16 bordoB1 padding5_0 center_p Lheight20_p h20_p bold_p">
<div class="grid_6">
<p class="bordoR marginR30">Umori</p>
</div>
<div class="grid_6">
<p class="bordoR bordoL3 marginL-30 marginR30">Generi</p>
</div>
<div class="grid_2">
<p class="bordoR bordoL3 marginL-30 marginR15">Dettagli</p>
</div>
<div class="grid_2">
<p class=" bordoL3 marginL-15">Utente</p>
</div>
</div>
{% endblock %}
{% block testata_a %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-30">
<a href="#" class="hover marginL30">Animazione</a><br>
<a href="#" class="hover marginL30">Avventura</a><br>
<a href="#" class="hover marginL30">Azione</a><br>
<a href="#" class="hover marginL30">Comici</a><br>
<a href="#" class="hover marginL30">Commedia</a><br>
<a href="#" class="hover marginL30">Documentari</a><br>
<a href="#" class="hover marginL30">Drammatici</a>
</p>
</div>
<div class="grid_2 margin10_0">
<p>
<a href="#" class="hover">Fantascienza</a><br>
<a href="#" class="hover">Fantasy</a><br>
<a href="#" class="hover">Fiabeschi</a><br>
<a href="#" class="hover">Gialli</a><br>
<a href="#" class="hover">Guerra</a><br>
<a href="#" class="hover">Horror</a><br>
<a href="#" class="hover">Musical</a>
</p>
</div>
<div class="grid_2 margin10_0">
<p class="bordoR marginR30">
<a href="#" class="hover">Noir</a><br>
<a href="#" class="hover">Polizieschi</a><br>
<a href="#" class="hover">Romantici</a><br>
<a href="#" class="hover">Thriller</a><br>
<a href="#" class="hover">Western</a><br>
<a href="#" class="hover">Proponi nuovo</a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a>
</p>
</div>
{% endblock %}
{% block testata_b %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-15">
<a href="#" class="hover marginL15">Consigliati per te</a><br>
<a href="#" class="hover marginL15">Piaciuti / Non piaciuti</a><br>
<a href="#" class="hover marginL15">Recensiti / Votati</a><br>
<a href="#" class="hover marginL15">Umore impostato</a><br>
<a href="#" class="hover marginL15">Segnala titolo assente</a><br>
<a href="#" class="hover marginL15">Visti</a><br>
<a href="#" class="hover marginL15">Top 10 / 50 / 100</a><br>
<a href="#" class="hover"></a>
<p></p>
</div>
{% endblock %}
{% block contenuto %}
{% for film in films %}
<div class="grid_4 marginB10 h205">
<div class="grid_2 Lheight10">
<a href="/Database/Film/{{ film.id }}"><img class="w120 h165 marginB5" src="Amore-e-altri-rimedi.jpg" ></a>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Visto:<span class="bold">No</span></p>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Umore:<span class="bold"></span></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="color marginL5 marginT-5 bordoB2 paddingB5 marginR10 size12">Voto: <img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="marginL5 bold color marginB10">{% for umori in film.umori.all %}{{ umori.umore }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{% for generi in film.generi.all %}{{ generi.genere }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{{ film.anno }}</p>
</div>
<div class="grid_2 Lheight12">
<p class="bold color marginL5 marginB10">{{ film.durata }} min.</p>
</div>
<div class="clear"> </div>
<div class="grid_2">
<h4><a class="black hover" href="/Database/Film/{{ film.id }}">{{ film.titolo }}</a></h4>
</div>
<div class="grid_2">
<p class="marginB10"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"></p>
</div>
</div>
{% endfor %}
<div class="grid_16 center">
{% if films.has_previous %}
<a class="color2 bold hover" href="?pagina={{ films.previous_page_number }}">precedente</a>
{% endif %}
{% for i in pagine %}
{% if i != films.number %}
<a class="black bold hover" href="?pagina={{ i }}">{{ i }}</a>
{% else %}
<a class="color1 bold line size20">{{ i }}</a>
{% endif %}
{% endfor %}
{% if films.has_next %}
<a class="color2 bold hover" href="?pagina={{ films.next_page_number }}">successivo</a>
{% endif %}
</div>
{% endblock %}
布拉尼.html
{% extends "Base.html" %}
{% block titolo %}Brani{% endblock %}
{% block personalizzazione %}
<style media="screen" rel="stylesheet" type="text/css">
#Brani {color:#FF0066; }
</style>
{% endblock %}
{% block testata %}
<div class="grid_16 bordoB1 padding5_0 center_p Lheight20_p h20_p bold_p">
<div class="grid_6">
<p class="bordoR marginR30">Umori</p>
</div>
<div class="grid_6">
<p class="bordoR bordoL3 marginL-30 marginR30">Generi</p>
</div>
<div class="grid_2">
<p class="bordoR bordoL3 marginL-30 marginR15">Dettagli</p>
</div>
<div class="grid_2">
<p class=" bordoL3 marginL-15">Utente</p>
</div>
</div>
{% endblock %}
{% block testata_a %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-30">
<a href="#" class="hover marginL30">Alternativa</a><br>
<a href="#" class="hover marginL30">Classica</a><br>
<a href="#" class="hover marginL30">Dance</a><br>
<a href="#" class="hover marginL30">Elettronica</a><br>
<a href="#" class="hover marginL30">Hip-Hop / Rap</a><br>
<a href="#" class="hover marginL30">Jazz</a><br>
<a href="#" class="hover marginL30">Pop</a>
</p>
</div>
<div class="grid_2 margin10_0">
<p>
<a href="#" class="hover">R&B / Soul</a><br>
<a href="#" class="hover">Reggae</a><br>
<a href="#" class="hover">Rock</a><br>
<a href="#" class="hover">Colonne sonore</a><br>
<a href="#" class="hover">World</a><br>
<a href="#" class="hover">Proponi nuovo</a><br>
<a href="#" class="hover"></a>
</p>
</div>
<div class="grid_2 margin10_0">
<p class="bordoR marginR30">
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a>
</p>
</div>
{% endblock %}
{% block testata_b %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-15">
<a href="#" class="hover marginL15">Consigliati per te</a><br>
<a href="#" class="hover marginL15">Piaciuti / Non piaciuti</a><br>
<a href="#" class="hover marginL15">Recensiti / Votati</a><br>
<a href="#" class="hover marginL15">Umore impostato</a><br>
<a href="#" class="hover marginL15">Segnala titolo assente</a><br>
<a href="#" class="hover marginL15">Ascoltati</a><br>
<a href="#" class="hover marginL15">Top 10 / 50 / 100</a><br>
<a href="#" class="hover"></a>
<p></p>
</div>
{% endblock %}
{% block contenuto %}
{% for brano in brani %}
<div class="grid_4 marginB10 h205">
<div class="grid_2 Lheight10">
<a href="/Database/Brano/{{ brano.id }}"><img class="w120 h165 marginB5" src="Amore-e-altri-rimedi.jpg" ></a>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Ascoltato:<span class="bold">No</span></p>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Umore:<span class="bold"></span></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="color marginL5 marginT-5 bordoB2 paddingB5 marginR10 size12">Voto: <img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="marginL5 bold color marginB10">{% for umori in brano.umori.all %}{{ umori.umore }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{% for generi in brano.generi.all %}{{ generi.genere }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{{ brano.anno }}</p>
</div>
<div class="grid_2 Lheight12">
<p class="bold color marginL5 marginB10">{{ brano.durata }} min.</p>
</div>
<div class="clear"> </div>
<div class="grid_2">
<h4><a class="black hover" href="/Database/Brano/{{ brano.id }}">{{ brano.titolo }}</a></h4>
</div>
<div class="grid_2">
<p class="marginB10"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"></p>
</div>
</div>
{% endfor %}
<div class="grid_16 center">
{% if brani.has_previous %}
<a class="color2 bold hover" href="?pagina={{ brani.previous_page_number }}">precedente</a>
{% endif %}
{% for i in pagine %}
{% if i != brani.number %}
<a class="black bold hover" href="?pagina={{ i }}">{{ i }}</a>
{% else %}
<a class="color1 bold line size20">{{ i }}</a>
{% endif %}
{% endfor %}
{% if brani.has_next %}
<a class="color2 bold hover" href="?pagina={{ brani.next_page_number }}">successivo</a>
{% endif %}
</div>
{% endblock %}
这是我的观点:
def films(request):
films = Film.objects.order_by("anno", "titolo")
paginator = Paginator( films, 2 )
try:
pagina = int( request.GET.get( "pagina", "1" ) )
except ValueError:
pagina = 1
try:
pagine = paginator.page( pagina )
except ( EmptyPage, InvalidPage ):
pagine = paginator.page ( paginator.num_pages )
return render_to_response('Films.html', { 'films': pagine, 'pagine': range( 1, paginator.num_pages + 1 ) } )
def brani(request):
brani = Brano.objects.order_by("anno", "titolo")
paginator = Paginator( brani, 2 )
try:
pagina = int( request.GET.get( "pagina", "1" ) )
except ValueError:
pagina = 1
try:
pagine = paginator.page( pagina )
except ( EmptyPage, InvalidPage ):
pagine = paginator.page ( paginator.num_pages )
return render_to_response('Brani.html', { 'brani': pagine, 'pagine': range( 1, paginator.num_pages + 1 ) } )
我只想有一个模板,因为它们实际上是相同的,我还想创建一个 def Pagination
来调用 def film
和 def brani
.
对于 {% block titolo %}
和我想更改的其他单词(如果是电影或brani 不是问题),我使用 {% iffilms %}
或 {% if brani %}
。
但如果我只想要一个,我不知道如何从 View 中的函数传递 'films': pagine
或 'brani': pagine
两者的功能分页。有人可以帮助我吗?
最佳答案
您可以使用 1.3 版以来可用的通用 ListView 来减少代码重复
from django.views.generic.list import ListView
class FilmListView(ListView):
model = Film
paginate_by = 10
page_kwarg = 'pagina'
context_object_name = "films"
class BranoListView(ListView):
model = Brano
paginate_by = 10
page_kwarg = 'pagina'
context_object_name = "brani"
然后您可以设置通用分页模板
{% extends "base.html" %}
{% block contenuto %}
{% block pagina %}
<div class="grid_16 center">
{% if objects.has_previous %}
<a class="color2 bold hover" href="?pagina={{ objects.previous_page_number }}">precedente</a>
{% endif %}
{% for i in paginator.page_range %}
{% if i == page.number %}
<a class="color1 bold line size20">{{ i }}</a>
{% else %}
<a class="black bold hover" href="?pagina={{ i }}">{{ i }}</a>
{% endif %}
{% endfor %}
{% if objects.has_next %}
<a class="color2 bold hover" href="?pagina={{ objects.next_page_number }}">successivo</a>
{% endif %}
</div>
{% block pagina %}
{% endblock %}
{% extends "pagination.html" %}
{% block titolo %}Films{% endblock %}
{% block personalizzazione %}
<style media="screen" rel="stylesheet" type="text/css">
#Films {color:#FF0066; }
</style>
{% endblock %}
{% block testata %}
<div class="grid_16 bordoB1 padding5_0 center_p Lheight20_p h20_p bold_p">
<div class="grid_6">
<p class="bordoR marginR30">Umori</p>
</div>
<div class="grid_6">
<p class="bordoR bordoL3 marginL-30 marginR30">Generi</p>
</div>
<div class="grid_2">
<p class="bordoR bordoL3 marginL-30 marginR15">Dettagli</p>
</div>
<div class="grid_2">
<p class=" bordoL3 marginL-15">Utente</p>
</div>
</div>
{% endblock %}
{% block testata_a %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-30">
<a href="#" class="hover marginL30">Animazione</a><br>
<a href="#" class="hover marginL30">Avventura</a><br>
<a href="#" class="hover marginL30">Azione</a><br>
<a href="#" class="hover marginL30">Comici</a><br>
<a href="#" class="hover marginL30">Commedia</a><br>
<a href="#" class="hover marginL30">Documentari</a><br>
<a href="#" class="hover marginL30">Drammatici</a>
</p>
</div>
<div class="grid_2 margin10_0">
<p>
<a href="#" class="hover">Fantascienza</a><br>
<a href="#" class="hover">Fantasy</a><br>
<a href="#" class="hover">Fiabeschi</a><br>
<a href="#" class="hover">Gialli</a><br>
<a href="#" class="hover">Guerra</a><br>
<a href="#" class="hover">Horror</a><br>
<a href="#" class="hover">Musical</a>
</p>
</div>
<div class="grid_2 margin10_0">
<p class="bordoR marginR30">
<a href="#" class="hover">Noir</a><br>
<a href="#" class="hover">Polizieschi</a><br>
<a href="#" class="hover">Romantici</a><br>
<a href="#" class="hover">Thriller</a><br>
<a href="#" class="hover">Western</a><br>
<a href="#" class="hover">Proponi nuovo</a><br>
<a href="#" class="hover"></a><br>
<a href="#" class="hover"></a>
</p>
</div>
{% endblock %}
{% block testata_b %}
<div class="grid_2 margin10_0">
<p class="bordoL4 marginL-15">
<a href="#" class="hover marginL15">Consigliati per te</a><br>
<a href="#" class="hover marginL15">Piaciuti / Non piaciuti</a><br>
<a href="#" class="hover marginL15">Recensiti / Votati</a><br>
<a href="#" class="hover marginL15">Umore impostato</a><br>
<a href="#" class="hover marginL15">Segnala titolo assente</a><br>
<a href="#" class="hover marginL15">Visti</a><br>
<a href="#" class="hover marginL15">Top 10 / 50 / 100</a><br>
<a href="#" class="hover"></a>
<p></p>
</div>
{% endblock %}
{% block contenuto %}
{{ block.super }}{# This will insert the pagination here #}
{% for film in films %}
<div class="grid_4 marginB10 h205">
<div class="grid_2 Lheight10">
<a href="/Database/Film/{{ film.id }}"><img class="w120 h165 marginB5" src="Amore-e-altri-rimedi.jpg" ></a>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Visto:<span class="bold">No</span></p>
</div>
<div class="grid_2 Lheight10">
<p class="color marginL5 marginB10 size12">Umore:<span class="bold"></span></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="color marginL5 marginT-5 bordoB2 paddingB5 marginR10 size12">Voto: <img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"></p>
</div>
<div class="grid_2 Lheight12 marginT5">
<p class="marginL5 bold color marginB10">{% for umori in film.umori.all %}{{ umori.umore }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{% for generi in film.generi.all %}{{ generi.genere }}<br>{% endfor %}</p>
</div>
<div class="grid_2 Lheight12">
<p class="marginL5 bold color marginB10">{{ film.anno }}</p>
</div>
<div class="grid_2 Lheight12">
<p class="bold color marginL5 marginB10">{{ film.durata }} min.</p>
</div>
<div class="clear"> </div>
<div class="grid_2">
<h4><a class="black hover" href="/Database/Film/{{ film.id }}">{{ film.titolo }}</a></h4>
</div>
<div class="grid_2">
<p class="marginB10"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"></p>
</div>
</div>
{% endfor %}
{{ block.super }}{# This will insert the pagination here #}
{% endblock %}
通过这种方式,您可以强制分离,以便在这些 View 的模板中只表示不同 View 之间不同的内容
引用:
关于python - 连接模板和 View 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16994341/
namespace std { template <> class hash{ public : size_t operator()( cons
我正在构建一个 Javascript 交互性有限的 Django 应用程序,并且正在研究如何将 Vue 模板与 Django 模板合并以实现相同的内容。 想象一个无限滚动的页面,其中 SEO 非常重要
我需要一个由游戏逻辑组成的外部类,调用 LitElement 组件,并向其传递一个 html 模板文字,该组件将使用该文字来更新其自己的 html 模板文字的一部分。 在下面的代码中,您将看到组件的一
很简单,我不想在 html 文件中定义所有 Handlebars 模板 我试过了 但这并没有奏效。我是否可以不以编程方式定义模板,甚至只是加载 Handlebars 文件,以便我可以重用,而且我觉得
在此代码中,j 正确地成为对象:j.name、j.addr、j.city、j.state 和 j.zip。但是,成功函数有一个 JavaScript 错误 .tmpl() 不是函数。 {{t
Django模板不会?点进来,总结了模板语法传值取值、过滤器和自定义过滤器、模板标签的分类、中间件403报错如何解决、如何继承模板~👆 Django 模板 模板传值取值 后端传值 键值对形式:{‘n
哈喽大家好,我是鹿 九 丸 \color{red}{鹿九丸}鹿九丸,今天给大家带来的是C++模板。 如果大家在看我的博客的过程中或者学习的过程中以及在学习方向上有什么问题或者想跟我交流的话可以加我的企
我正在用 PHP 编写一个简单的模板层,但我遇到了一些困难。目前它是这样工作的: 首先,我使用 fetch_template 从数据库中加载模板内容 - 这可行(如果您有兴趣,我会在启动时收集所有模板
我正在制作有关模板的 Django 教程。我目前处于此代码: from django.template import Template, Context >>> person = {'name': '
我正在使用 Jquery 模板来显示传入的 JSON 数据我想将模板加载到可缓存的外部文件中。我该怎么做? 更新 http://encosia.com/2010/12/02/jquery-templa
这是我的观点.py: from django.http import HttpResponse from django.template.loader import get_template from
我试图说服一位同事在项目的前端使用 Mustache/Hogan,我提出了以下建议: 有一个 templates.js 文件,大致如下所示: var tpl_alert = '{{msg}}'; va
我想创建一个通用的数组函数。在我的 API 中,我有一个通用容器,我需要将其转换为正确的类,但我想让它通用 template void UT::printArray(CCArray* arr, T t
有谁知道是否有办法在 Genshi 中创建 javascript 模板?我的意思是,我需要一个 .js 文件,可以在其中使用 等指令。等等。 有什么想法吗?谢谢! 最佳答案 你可以直接在html中这
我想知道是否可以设置某种 HTML 模板系统,基本上我有 3 个不同的文件: - header.html - footer.html - landing.html(landing.html 是包含页面
我正在尝试构建以下 HTML 模板: 这很简单,如果我使用红色容器 1-4,语法如下: 1 2 3 4 5 6 7 8 9 https://jsfi
#include "boost/numeric/ublas/matrix.hpp" using namespace boost::numeric::ublas; template class Lay
我在一个类中有一个函数,它传递了一个函数及其参数,然后将它们绑定(bind)到一个函数调用中并调用该函数等。 这已经被快速组合在一起以测试我知道代码不是很好的概念。 class Profiling {
是否有一个 c++ 结构或模板(在任何库中)允许我在十进制和任何其他基数之间进行转换(很像 bitset 可以做的)? 最佳答案 是的,你可以使用unsigned int: unsigned int
数据类型给程序设计带来的困扰及解决方案 int maxt(int, int); double maxt(double, double); 若有一种占位符T,能够代替类型,便可以简化代码的冗余编写
我是一名优秀的程序员,十分优秀!