Python Lover(4)Django Doc - CSS and Deployment
1. Easy Way to Serve the Static Files
Have the static resources under here
easypoll/polls/static/polls/style.css
li a {
color: green;
}
Adding this on the html template, for example, index.html
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
2. Deploying Django
I used to use nginx + fastcgi, fastcgi implementation is FLUP. I would like to try WSGI this time.(Python Web Server Gateway Interface)
2.1 Choose to Try gunicorn
Install pip first
https://pip.pypa.io/en/latest/installing.html#install-or-upgrade-pip
>wget https://bootstrap.pypa.io/get-pip.py
>sudo python get-pip.py
Password: Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages Cleaning up...
The problem is that when I install python, I only soft link the python command. Actually I should link this directory to class path.
/Library/Frameworks/Python.framework/Versions/3.4/bin
Soft link in that directory
>sudo ln -s python3 python
>sudo ln -s pip3 pip
>pip -V
pip 1.5.6 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
Install gunicorn
http://docs.gunicorn.org/en/latest/install.html
>pip install gunicorn
Downloading/unpacking gunicorn Downloading gunicorn-19.1.1-py2.py3-none-any.whl (104kB): 104kB downloaded Installing collected packages: gunicorn Successfully installed gunicorn Cleaning up...
Install greenlet
>pip install greenlet
2 Options here
http://eventlet.net/
It uses epoll or kqueue or libevent for highly scalable non-blocking I/O
>pip install eventlet
http://gevent.org/
Fast event loop based on libev (epoll on Linux, kqueue on FreeBSD)
>pip install gevent
It runs on my machine
>gunicorn easypoll.wsgi
Settings
http://docs.gunicorn.org/en/latest/settings.html#settings
http://docs.gunicorn.org/en/latest/configure.html
Example of the configuration file
https://github.com/rdegges/django-skel/blob/master/gunicorn.py.ini
https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py
>sudo gunicorn -c gunicorn.py.ini easypoll.wsgi
my configuration file should be as follow:
>cat gunicorn.py.ini
"""gunicorn WSGI server configuration."""
import multiprocessing
bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1
2.2 Install on ubuntu
Actually I should run it on ubuntu system or similar
>sudo apt-get install python-software-properties
>sudo apt-add-repository ppa:gunicorn/ppa
>sudo apt-get update
Not working on ubuntu14.04
>sudo add-apt-repository --remove ppa:gunicorn/ppa
>sudo apt-get install gunicorn
>sudo apt-get install python-pip
>sudo pip install greenlet
>sudo pip install eventlet
>sudo pip install gevent
>sudo gunicorn -c gunicorn.py.ini easypoll.wsgi
Error Message
ImportError: No module named django.core.wsgi
Solution:
>python -V
Python 2.7.6
>sudo rm -fr python
>sudo ln -s python3 python
Download the django package
>wget https://www.djangoproject.com/m/releases/1.7/Django-1.7.tar.gz
>sudo python setup.py install
Error Message
ImportError: No module named 'setuptools'
Solution:
Install setuptools
https://pypi.python.org/pypi/setuptools
>wget https://pypi.python.org/packages/source/s/setuptools/setuptools-5.7.tar.gz
>cd /home/carl/download/install/setuptools-5.7
>sudo python setup.py install
>cd /home/carl/download/install/Django-1.7
>sudo python setup.py install
Error Message
>gunicorn -c gunicorn.py.ini easypoll.wsgi
Traceback (most recent call last): File "/usr/bin/gunicorn", line 5, in <module> from pkg_resources import load_entry_point File "<frozen importlib._bootstrap>", line 2214, in _find_and_load File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible File "/usr/local/lib/python3.4/dist-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 2872, in <module> File "/usr/local/lib/python3.4/dist-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 449, in _build_master File "/usr/local/lib/python3.4/dist-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 745, in require File "/usr/local/lib/python3.4/dist-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 639, in resolve pkg_resources.DistributionNotFound: gunicorn==17.5
Solution:
>sudo easy_install --upgrade pip
>sudo apt-get install python3.4-dev
>sudo pip install greenlet
>sudo pip install eventlet
>sudo pip install gevent
Should install Gunicorn like this.
>sudo pip install git+https://github.com/benoitc/gunicorn.git
>sudo apt-get install python3-pip
It works then.
>gunicorn -c gunicorn.py.ini easypoll.wsgi
But when I visit the admin page, I get some problem with the static pages.
Static Configuration on easypoll/settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = "/home/carl/work/easy/easypoll/static/"
STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.FileSystemFinder', )
Copy and Collect all the static files to directly
>python manage.py collectstatic
We can point the nginx to that place if we want.
Command to clean the PYC files.
>pyclean .
Finally, I found it is fine to using python 2.7.6.
And we can change the conf file like this.
carl@ubuntu-slave2:~/work/easy/easypoll$ cat gunicorn.py.ini
"""gunicorn WSGI server configuration."""
import multiprocessing
bind = "0.0.0.0:8000"
workers = multiprocessing.cpu_count() * 2 + 1
#worker_class = 'eventlet'
#worker_class = 'sync'
worker_class = 'gevent'
References:
More Topic
https://docs.djangoproject.com/en/1.7/topics/
Look and Feel
https://docs.djangoproject.com/en/1.7/intro/tutorial06/
How to deploy
https://docs.djangoproject.com/en/1.7/howto/deployment/
Spawn-fcgi, wsgi, fastcgi, cgi
http://lihuipeng.blog.51cto.com/3064864/890573
http://sillycat.iteye.com/blog/582074
http://lutaf.com/141.htm
http://docs.gunicorn.org/en/latest/deploy.html
https://pip.pypa.io/en/latest/installing.html#install-or-upgrade-pip
http://stackoverflow.com/questions/20181121/django-admin-not-working-ugly-serving-with-nginx-and-gunicorn
相关推荐
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用
Python在线考试系统后端-大学毕业设计-基于Django+Django -Rest-Framework 适合大学生计算机专业的毕业设计,课程设计。 Python在线考试系统后端-大学毕业设计-基于Django+Django -Rest-Framework 适合大学生...
资源分类:Python库 所属语言:Python 资源全名:Django-3.2.11-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:djangocms-cameraslider-0.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
【Python库 | djangocms-responsive-wrapper-0.2.0.tar.gz】 在Python的世界里,库是开发者的重要工具,它们提供了丰富的功能,使我们能够更高效地编写代码。"djangocms-responsive-wrapper"是一个专门针对Django ...
资源分类:Python库 所属语言:Python 资源全名:django-cascading-dropdown-widget-0.2.6.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:django-wkhtmltopdf-3.2.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
django-python3-ldap, python 3的Django LDAP用户身份验证后端 django-python3-ldapdjango-python3-ldap 为 python 2和 3提供了一个 Django LDAP用户身份验证后端。特性使用LDAP服务器验证用户身份。将LDAP用户与...
本源码提供了一个基于Python和Vue的Django-Vue-Lyadmin前后端分离低代码快速开发平台设计。项目包含856个文件,其中包括362个JavaScript文件、157个Vue文件、150个Python文件、67个CSS样式文件、46个PNG图片、13个...
支持python3.6Django2.0-goflow 工作流引擎 a
项目概述:django-lb-workflow 是一个基于Python的高效易用Django流程引擎源码,旨在轻松集成至现有系统。该项目主要由68个Python文件、30个HTML文件以及其他相关文件构成,共计136个文件。其中还包括了HTML模板、...
标题中的"Python库 | django-bs4-0.0.3.tar.gz"指的是一个基于Python的Web开发框架Django的一个扩展库,它与Bootstrap 4框架相结合。这个版本是0.0.3,被打包成tar.gz格式的压缩文件。这种类型的文件通常用于分发源...
资源分类:Python库 所属语言:Python 资源全名:django-pyodbc-azure-1.2.10.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:django-adminlte-ui-1.3.0b0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:django-workflow-system-0.6.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
4. `django-sse`主要用于后端开发,与Django框架配合构建Web应用。 5. 库的使用遵循Python开发语言的规范,可被其他Python项目引用。 6. 解压后的`.tar.gz`文件可能包含README、LICENSE、setup.py、requirements.txt...
资源分类:Python库 所属语言:Python 资源全名:django-pyodbc-azure-1.0.11.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059