博文

目前显示的是标签为“Django”的博文

Enable HTTPS on localhost with NGINX

# Enable HTTPS on localhost with NGINX From: [digitalocean](https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-16-04) # 1. Create a self-signed key and certificate pair ```bash sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.cer # Note: digitalocean use extension .crt not .cer. ``` *[req](# 'We want to use X.509 certificate signing request (CSR) management.'). [X.509](# 'Is a public key infrastructure standard. It specifies that we want to make a self-signed certificate instead of generating a certificate signing request'). [nodes](# 'Stop encrypting certificate with a passphrase. We need Nginx to be able to read the file, without user intervention'). [days](# 'Valid days before expire.'). [newkey](# 'Generate a new certificate and a new key at the same time.'). [rsa:2048](# 'To m...

为Django配置PostgreSQL数据库

摘自: [digitalocean](https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-django-application-on-ubuntu-14-04) ### 1. 更新软件源 最好更新,像在路由器OpenWRT中,不更新就找不到包。 `sudo apt-get update` ### 2. 审核教程给的代码 ```bash sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib ``` 结论:无毒,必要,可以复制了按回车运行。 `python3`,就用第3版,迟早要升级的。  `python3-dev`:开发全套装上,不带dev的python是给用户用的,应该少了很多东西;  `pip`:python用它来装程序;  `libpq-dev`:包含了你为PSQL开发第三方应用所需要的必备精简文件;  `postgregresql`:本文主角;  `postgregresql-contrib`:更多功能。  ### 3. 配置PostgreSQL ```bash #切换成postgres用户。这个用户名是刚才安装的东西所创建的。 sudo su - postgres #进入数据库命令行 psql #创建数据库名 CREATE DATABASE googlesite; #创建数据库用户和密码。暂时不针对哪个特定的数据库。 CREATE USER googlesiteuser WITH PASSWORD 'NoPaSsWoRd'; #防止编码问题。使用万国码,Django也推荐你用utf-8。 ALTER ROLE googlesiteuser SET client_encoding TO 'utf8'; #只让django、googlesiteuser读取已经提交了的操作。提交:数据库用语,比如转账,扣钱、加钱都完成后才提交,还没加钱你就想读这行数据,不给。 ALTER ROLE googlesiteuser SET ...

From Heroku to PythonAnywhere

Heroku ------ Heroku free account is good for presentation objects. The bad news is: 1. Sleep/destroied after 15 minutes in active. Recreate app after revisit. 1. So, any new files or file type database modification are lost. e.g. Sqlite. 1. Max 10,000 rows in Postgres on Heroku for free account.  My ja-en dictionary contains 320,000 entrys. Multiple databases in Django with `db.sqlite3` containing read-only dictionary? I don't wanna bother that yet. PythonAnywhere ------ After some digging, I found that PythonAnywhere is an awesome replacement (both free accounts). 1. It's like a free limited VPS. - you can open a shell like in Linux. - you can setup new `virtualenv`. - you can pip install packages from Pipe/GitHub. - no file loss (I think). 1. Upload Django project, config, and reload, and then your site is up. Just walk through their tutorials. It's pretty stright forward. 1. Free usage for 3 months, can extend un-limit(unknown) times. 1. Free MySQL...

Django项目部署到Heroku Demo要注意的事项

1. 复制一份项目, 用于修改并部署到Heroku. 删除 .git 文件夹, virtualenv 文件夹. 2. 进入复制的项目, git init 3. 添加 .env 到 .gitignore 4. git commit 5. heroku create 6. git remote -v 将会有类似的输出(.git前面的字符用于下一步): heroku  https://git.heroku.com/falling-wind-1624.git (fetch) 7. heroku git:remote -a falling-wind-1624 8. git push heroku master ``` pip freeze > requirements.txt Add Procfile install gunicorn install whitenoise to serve static files add app domain to ALLOWED_HOSTS don't overwrite server database (local move out, git commit, .gitignore, move in, push) git push heroku master heroku logs --source app --tail ```

Django Overwrite Templates of Any App

1. Create folder under Django root folder:  root/`templates/target app/*any new template you want*.html` 1. Add `os.path.join(BASE_DIR, 'templates')` into `'DIRS'` setting. ```python # settings.py TEMPLATES = [     {         'DIRS': [os.path.join(BASE_DIR, 'templates')], ```