基于 Django 的短网址程序. An English version follows.
Django 支持的 Python3 版本
处了pip install -r requirements.txt
, 还可能需要数据库驱动和 web 服务器
- 请把自定义模板放置于
templates
; - 请将生产环境的配置写在
djanurl/production.py
; - 需要运行
python manage.py collectstatics
. 这需要设置STATIC_ROOT
; - 在
production.py
设置EXPLICIT_REDIRECT = True
开启显式跳转; - 显式跳转模板请创建到自定义模板目录的
surl/redirect.html
, 可参考 surl 这个 app 的模板; - 默认开启 i18n 和 i10n, 网站语言根据浏览器/系统语言自动判断.
A Django based url shortener project.
This project is written in Python3. It should work well with all the versions that Django supports.
In addition to pip install -r requirements.txt
, you may also need to install database drivers and http/wsgi servers.
- You should put your own templates in the
templates
folder in the project root directory; - You may have your production settings set in
djanurl/production.py
- You might need to run
python manage.py collectstatics
. In order to do this, you should haveSTATIC_ROOT
set in your settings - Set
EXPLICIT_REDIRECT = True
inproduction.py
to enable explicit redirection - Template used in explicit redirection is located at
surl/redirect.html
- i18n and i10n is enabled by default. Language code is detected based on browser and os languages.
File 1: uwsgi.ini
[uwsgi]
socket=/tmp/ovz.im.sock
home=/path/to/virtualenv/
chdir=/path/to/project/
env=DJANGO_SETTINGS_MODULE=djanurl.settings
module=djanurl.wsgi:application
master=True
workers=8
pidfile=/tmp/ovz.im.pid
max-requests=5000
thunder-lock=True
vacuum=True
harakiri=120
File 2: supervisord.conf
....
[program:ovzim]
command = /path/to/uwsgi --ini /path/to/uwsgi.ini
stopsignal=QUIT
autostart=true
autorestart=true
stdout_logfile=/var/logs/ovz.log
redirect_stderr=true
File 3: nginx configuration ovz.im.conf
upstream ovzim {
server unix:https:///tmp/ovz.im.sock;
}
server {
listen 80;
server_name www.ovz.im;
return 302 $scheme:https://ovz.im$request_uri;
}
server {
listen 80;
server_name ovz.im;
charset utf-8;
client_max_body_size 75M;
location /static {
root /path/to/project/;
}
location / {
uwsgi_pass ovzim;
include uwsgi_params;
}
}