Skip to content

grb2015/django-blog-tutorial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

免费、中文、零基础,完整的项目,基于最新版 Django 1.10 和 Python 3.5。带你从零开始一步步开发属于自己的博客网站,帮助你以最快的速度掌握 Django 开发的技巧。

资源列表

分支说明

每篇教程的代码都位于项目相应的分支中,点击上方的 Branch 按钮可以查看到,例如分支 Step1_build-development-environment 对应第 1 篇教程 1 - 搭建开发环境

master 主分支是项目的完整代码。

demo 分支是演示项目的分支代码。

在本地运行项目

  1. 克隆项目到本地

    打开命令行,进入到保存项目的文件夹,输入如下命令:

    git clone https://github.com/zmrenwu/django-blog-tutorial.git
    
  2. 创建并激活虚拟环境

    在命令行进入到保存虚拟环境的文件夹,输入如下命令创建并激活虚拟环境:

    virtualenv blogproject_env
    
    # windows
    blogproject_env\Scripts\activate
    
    # linux
    source blogproject_env/bin/activate
    

    关于如何使用虚拟环境,参阅:搭建开发环境 的 Virtualenv 部分。如果不想使用虚拟环境,可以跳过这一步。

  3. 安装项目依赖

    如果使用了虚拟环境,确保激活并进入了虚拟环境,在命令行进入项目所在的 django-blog-tutorial 文件夹,运行如下命令:

    pip install -r requirements.txt
    
  4. 迁移数据库

    在上一步所在的位置运行如下命令迁移数据库:

    python manage.py migrate
    
  5. 创建后台管理员账户

    在上一步所在的位置运行如下命令创建后台管理员账户

    python manage.py createsuperuser
    

    具体请参阅 在 Django Admin 后台发布文章

  6. 运行开发服务器

    在上一步所在的位置运行如下命令开启开发服务器:

    python manage.py runserver
    

    在浏览器输入:127.0.0.1:8000

  7. 进入后台发布文章

    在浏览器输入:127.0.0.1:8000/admin

    使用第 5 步创建的后台管理员账户登录

    具体请参阅 在 Django Admin 后台发布文章

教程目录索引

基础部分

进阶部分

交流讨论和继续学习 Django

这里汇聚了大量经验丰富的 Django 开发者,遇到问题随时请教,以及获取更多的 Django 学习资料。

renbin.guo added 2017/09/24

遇到的问题:

1. 我这边没有域名,只有IP ,所以

/etc/nginx/sites-available/emo.zmrenwu.com
要进行修改:
#server_name demo.zmrenwu.com;
server_name localhost;

2. 遇到了访123.207.55.189总是出现的为nginx首页的页面。

解决方法:
因为我们设置了自己的配置文件,
/etc/nginx/sites-available/emo.zmrenwu.com
重启ubuntu即可,下次就好了。

##renbin.guo add 2017/10/14
day8 要注意,创建的base.html 不是和detail.html一个目录,而是在上一级目录

rbguo added 20180617 在aws上部署

/etc/nginx/nginx.conf下的配置:(centos上面没有sites-available/ sites-enabled 直接在/etc/nginx/nginx.conf下面配置)
include /etc/nginx/default.d/*.conf;

    #location / {  
    #}  
    location /static {  
    #alias /root/djongo_blog/django-blog-tutorial/static;   
    alias /var/www/django-blog-tutorial/static;  
    }  
    location / {  
            proxy_set_header Host $host;  
            #proxy_pass http://unix:/tmp/site.sock;  
            proxy_pass http://unix:/tmp/demo.zmrenwu.com.socket;  

    #proxy_pass http://127.0.0.1:8000;  
    }  

vim /lib/systemd/system/nginx.service

然后完了如果出错,

  nginx error!  
  The page you are looking for is temporarily unavailable. Please try again later.  

  Website Administrator  
  Something has triggered an error on your website. This is the default error page for nginx that is distributed with Amazon Linux 2. It is located /usr/share/nginx/html/50x.html

  You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.  

[ Powered by nginx ] [ Powered by Amazon Linux 2 ]
" 这样的话就需要修改:
可以通过tail -f /var/log/nginx/error.log查看log
会发现是报socket无法找到:
需要如下修改
vim /lib/systemd/system/nginx.service
PrivateTmp=false

另外:不要把源码放在/root下
不然后面nginx进程无法访问,我是放在/var/www下的

自动启动 Gunicorn这个还没做,有时间了加上,现在已经可以自由访问了!

Q5 AWS如何安装nginx等
https://stackoverflow.com/questions/37082406/how-to-install-nginx-1-9-15-on-amazon-linux-disto

View list of packages to install

amazon-linux-extras list
sudo amazon-linux-extras install nginx1.12

About

基于 Python3.5 和 Django 1.10 的 Django Blog 项目。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 49.6%
  • Python 38.2%
  • HTML 9.6%
  • JavaScript 2.4%
  • DIGITAL Command Language 0.2%