简体   繁体   English

将Python添加到Twitter Bootstrap

[英]Adding Python to Twitter Bootstrap

This may be a noob question but I am wondering about adding Python to Twitter Bootstrap (both of which i am only learning) 这可能是一个noob问题,但我想知道将Python添加到Twitter Bootstrap(我只是在学习)

Can anyone give me some idea of the folder structure i should have? 任何人都可以给我一些我应该拥有的文件夹结构的想法吗? I assume my Python folder goes at the same level as my Bootstrap project folder? 我假设我的Python文件夹与我的Bootstrap项目文件夹处于同一级别?

eg 例如

MyProject/
|-- Python/
|   |-- bin
|   |   |-- app.py
|   |-- docs
|   |-- sessions
|   |-- tests
|   |   |-- project_tests.py
|   
|-- bootstrap/
|   |-- css
|   |   |-- bootstrap.css
|   |   |-- bootstrap.min.css
|   |   
|   |-- js
|   |   |-- bootstrap.js
|   |   |-- bootstrap.min.js
|   |-- img
|   |   |-- glyphicon-halflings.png.
|   |   |-- glyphicon-halflings.png.

I got the bootstrap file structure straight from the download site and i am looking at this question here regarding best method to set up Python directories 我直接从下载站点获得了bootstrap文件结构,我在这里看到关于设置Python目录的最佳方法的这个问题

As always, thanks in advance. 一如既往,先谢谢。

Regardless of framework or whether you use one or not, it's best to have a single place to keep your static files (which would be all your twitter bootstrap contents). 无论是否使用框架,无论是否使用框架,最好有一个地方来保存静态文件(这将是您的所有Twitter引导程序内容)。

Personally I keep mine split into img , css , js , fonts for clarity. 我个人保持我的分裂为imgcssjsfonts以保持清晰。 Like so: 像这样:

MyProject/
|-- Python/
|   |-- bin
|   |   |-- app.py
|   |-- docs
|   |-- sessions
|   |-- tests
|   |   |-- project_tests.py
|   
|-- static/
|   |-- css/
|   |   |-- bootstrap.css
|   |   |-- bootstrap.min.css
|   |   |-- my_custom_styles.css
|   |-- js/
|   |   |-- bootstrap.js
|   |   |-- bootstrap.min.js
|   |-- img/
|   |   |-- glyphicon-halflings.png
|   |   |-- glyphicon-halflings.png
|   |-- fonts/
|   |   |-- cool_font

This has the benefit that when you use a web server to serve your static content you can use /static/ in your templates and point it to the /static/ folder on your filesystem. 这样做的好处是,当您使用Web服务器来提供静态内容时,您可以在模板中使用/static/并将其指向文件系统上的/static/文件夹。 Example with Nginx: Nginx的示例:

location ~ ^/static/  {
      alias    /path/to/static/;
      expires 30d;
    }

so www.yoururl.com/static/img/glyphicon-halflings.png is easy to find and serve from your filesystem. 所以www.yoururl.com/static/img/glyphicon-halflings.png很容易从你的文件系统中找到并提供服务。

As an added bonus, if you are developing for the web with Python there are some great frameworks out there to help you with a lot of the basics. 作为一个额外的好处,如果您使用Python开发Web,那么有一些很棒的框架可以帮助您完成许多基础知识。 They also have extensive documentation on handling static files in development and production deployment. 他们还有关于在开发和生产部署中处理静态文件的大量文档。

I've used: 我用过:

But there is also: 但也有:

And more ! 还有更多

Edit1 - Additional Bonus information: Edit1 - 额外奖励信息:

I said I'd add a little extra. 我说我会多补充一点。 Here's how I manage my static files: 以下是我管理静态文件的方法:

When I use Django, I use django-compressor , which will automatically combine and minimise inline CSS and JS in the templates. 当我使用Django时,我使用django-compressor ,它会自动组合并最小化模板中的内联CSS和JS。 It also adds a unique identifying hash so you can set cache headers for years into the future to save bandwidth and decrease loading times. 它还添加了一个唯一的标识哈希,因此您可以在未来几年内设置缓存标头,以节省带宽并减少加载时间。 If you change your static files, it automatically modifies the hash - they're re-downloaded by the browser. 如果您更改静态文件,它会自动修改哈希 - 它们会被浏览器重新下载。

If I'm using Flask (or something not-django), I use Grunt. 如果我正在使用Flask(或者不是-django),我会使用Grunt。 Although not really meant for python development, it's easy to hook into a continuous integration system (like Jenkins) and will also combine, concatenate and compress your CSS and JS for you. 虽然不是真正意义上的python开发,但它很容易挂钩到一个持续集成系统(如Jenkins),并且还将为您组合,连接和压缩您的CSS和JS。 Still haven't solved the unique hash though. 虽然还没有解决这个独特的哈希问题。

These new, compressed files, I put into a new directory - static-min . 这些新的压缩文件,我放入一个新目录 - static-min I then have a bash script, that loops through all the files in my static-min directory and gzips them (with 10 - the max gzip compression) but keeps their name the same. 然后我有一个bash脚本,它遍历我的static-min目录中的所有文件并对它们进行gzip(使用10 - 最大gzip压缩),但保持其名称相同。 This is so that if a supported browser requests your site - Nginx will serve the compressed static files. 这样,如果受支持的浏览器请求您的站点 - Nginx将提供压缩的静态文件。

Like so: 像这样:

|-- static-min/
|   |-- css/
|   |   |-- all_css_concatenated_minimised-723974hgjsf.css
|   |   |-- all_css_concatenated_minimised-723974hgjsf.css.gz
|   |-- js/
|   |   |-- all_js_concatenated_minimised-djad7rhea8f.js
|   |   |-- all_js_concatenated_minimised-djad7rhea8f.js.gz

Nginx config - the expires max will get the user to keep the file in their browser cache forever: Nginx配置 - expires max将使用户永久保存文件在其浏览器缓存中:

location ~ ^/static-min/  {
      alias    /path/to/static-min/;
      expires  max;
    }

Bootstrap是一个仅限客户端的库,因此为了保持一致性,您可能应该将它放在static/lib/bootstrap类的东西中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM