小编mrr*_*ot5的帖子

Jinja2 检查字典列表中是否存在值

我试图用字典检查列表中是否存在一个值。我使用烧瓶 1.0.2。请参阅下面的示例:

person_list_dict = [
    {
        "name": "John Doe",
        "email": "johndoe@mydomain.com",
        "rol": "admin"
    },
    {
        "name": "John Smith",
        "email": "johnsmith@mydomain.com",
        "rol": "user"
    }
]
Run Code Online (Sandbox Code Playgroud)

我找到了两种方法来解决这个问题,你能告诉我哪个更好吗?:

第一个选项:jinja2 内置模板过滤器“map”

<pre>{% if "admin" in person_list_dict|map(attribute="rol") %}YES{% else %}NOPE{% endif %}</pre>
# return YES (john doe) and NOPE (john smith)
Run Code Online (Sandbox Code Playgroud)

第二个选项:Flask 模板过滤器

烧瓶代码:

@app.template_filter("is_in_list_dict")
def is_any(search="", list_dict=None, dict_key=""):
    if any(search in element[dict_key] for element in list_dict):
        return True
    return False
Run Code Online (Sandbox Code Playgroud)

模板代码:

<pre>{% if "admin"|is_in_list_dict(person_list_dict, "rol") %} YES {% else %} NOPE {% endif %}</pre> …
Run Code Online (Sandbox Code Playgroud)

python templates jinja2 flask python-3.x

6
推荐指数
1
解决办法
2万
查看次数

codeigniter javascript not found错误

首先,我很抱歉我的英语不好,我很西班牙语,如果我做错了,我很抱歉,这是我的第一篇文章.

我在codeigniter 2.1.4中加载javascript文件时遇到问题.我没有把它加载到我页面的标题中.css文件装得很好.此示例尝试加载jquery和bootstrap.

我正在遵循codeigniter文档中的步骤,当我创建codeigniter静态页面"home.php"时,我想使用bootstrap进行设计.

我遵循的教程是:http: //ellislab.com/codeigniter/user-guide/tutorial/static_pages.html

我的文件夹结构:

  • htdocs目录
    • myproject(课程)
      • 应用
        • 调节器
          • pages.php
        • 意见
          • 模板
            • header.php文件
          • 网页
            • home.php
            • about.php
      • 系统
      • 资产
        • 引导
          • CSS
            • bootstrap.min.css
          • JS
            • bootstrap.min.js
        • jquery- 2.1.0.min.js

我一直在这个论坛和其他人搜索,我总是找到与base_url()或site_url()相同的例子.这些是我的:

更新的代码:

<script type="text/javascript" src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

我的autoload.php加载了url helper:

$ autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)

当我尝试加载页面时,我收到以下错误:

GET http://localhost/curriculos/assets/jquery-2.1.0.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found) 
Run Code Online (Sandbox Code Playgroud)

最奇怪的是,当你点击其中一个时,它会向你显示文件类型正在尝试加载为text/html,而不是像往常一样加载应用程序/ javascript:

加载时出错:文件类型为text/html

你能帮助我吗?

非常感谢您的回复.

javascript php jquery codeigniter twitter-bootstrap

3
推荐指数
1
解决办法
5797
查看次数

Twitter Bootstrap 3响应全高度网格

首先,抱歉我的英语不好:S.我想要一个响应全高度网格使用bootstrap 3.我的问题是网格,我不知道如何设置100%高度容器和内部div.宽度是完美的但高度:S.

我尝试使用这个CSS,但它不起作用:

html body .container-fluid{
min-height:100%;
height:100%;
}

.border3{
min-height:20%;
height:20%;
}

.border4{
min-height:20%;
height:20%;
}

.border5{
min-height:20%;
height:20%;
}
Run Code Online (Sandbox Code Playgroud)

HTML + CSS:http://jsfiddle.net/z5dpu7od/1/

也许我可以用JavaScript解决这个问题.我可以采用浏览器高度并将其应用于.container-fluid元素,但我想仅使用CSS进行尝试.

感谢您的回答 :).

html css fullscreen responsive-design twitter-bootstrap-3

3
推荐指数
1
解决办法
5万
查看次数

Bootstrap 4小吃吧/吐司

我正在尝试使用Bootstrap 4创建一个快餐/吐司版。我从w3schools的本教程开始。

更新:我正在尝试为Bootstrap 4实现自定义小吃栏或吐司,但是现在,由于@Zim所说,Bootstrap 4包含了4.2版中的此选项,因此没有必要。

notifications toast twitter-bootstrap snackbar bootstrap-4

1
推荐指数
2
解决办法
2万
查看次数