Django 开发blog未完待续
[root@sishen simpleblog]# python3.5
Python 3.5.4 (default, Sep 20 2017, 20:37:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@sishen simpleblog]# python3 -m venv myvenv
[root@sishen simpleblog]# source myvenv/bin/activate
(myvenv) [root@sishen simpleblog]# pip install django==1.9.5
Collecting django==1.9.5
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)
100% |████████████████████████████████| 6.6MB 59kB/s
Installing collected packages: django
Successfully installed django-1.9.5
(myvenv) [root@sishen simpleblog]# django-admin.py startproject mysite
(myvenv) [root@sishen simpleblog]# tree mysite/
mysite/
├── manage.py
└── mysite
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
1 directory, 5 files
(myvenv) [root@sishen simpleblog]# cd mysite/
(myvenv) [root@sishen mysite]# ls
manage.py mysite
(myvenv) [root@sishen mysite]# cd mysite/
(myvenv) [root@sishen mysite]# pwd
/root/simpleblog/mysite/mysite
(myvenv) [root@sishen mysite]# ls
__init__.py settings.py urls.py wsgi.py
(myvenv) [root@sishen mysite]# vim settings.py
(myvenv) [root@sishen mysite]# vim settings.py
(myvenv) [root@sishen mysite]# cd ..
(myvenv) [root@sishen mysite]# python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, sessions, contenttypes, auth
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying sessions.0001_initial... OK
(myvenv) [root@sishen mysite]# python3 manage.py runserver 192.168.152.128:8000
Performing system checks...
System check identified no issues (0 silenced).
November 16, 2017 - 21:14:58
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://192.168.152.128:8000/
Quit the server with CONTROL-C.
Not Found: /
[16/Nov/2017 21:15:28] "GET / HTTP/1.1" 200 1767
Not Found: /favicon.ico
[16/Nov/2017 21:15:28] "GET /favicon.ico HTTP/1.1" 404 1942
^C(myvenv) [root@sishen mysite]# python3 manage.py startapp blog
(myvenv) [root@sishen mysite]# pwd
/root/simpleblog/mysite
(myvenv) [root@sishen mysite]# ls
blog db.sqlite3 manage.py mysite
(myvenv) [root@sishen mysite]# tree .
.
├── blog
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── db.sqlite3
├── manage.py
└── mysite
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── settings.cpython-35.pyc
│ ├── urls.cpython-35.pyc
│ └── wsgi.cpython-35.pyc
├── settings.py
├── urls.py
└── wsgi.py
4 directories, 17 files
(myvenv) [root@sishen mysite]# vim mysite/settings.py
(myvenv) [root@sishen mysite]# cd blog/
(myvenv) [root@sishen blog]# ls
admin.py apps.py __init__.py migrations models.py tests.py views.py
(myvenv) [root@sishen blog]# vim models.py
Error detected while processing /etc/vimrc:
line 15:
E492: Not an editor command: expandtab
Press ENTER or type command to continue
(myvenv) [root@sishen blog]# vim models.py
(myvenv) [root@sishen blog]# vim models.py
(myvenv) [root@sishen blog]# cd ..
(myvenv) [root@sishen mysite]# python3 manage.py makemigrations blog
Migrations for 'blog':
0001_initial.py:
- Create model Post
(myvenv) [root@sishen mysite]# python3 manage.py migrate blog
Operations to perform:
Apply all migrations: blog
Running migrations:
Rendering model states... DONE
Applying blog.0001_initial... OK
(myvenv) [root@sishen mysite]# python3 manage.py shell
Python 3.5.4 (default, Sep 20 2017, 20:37:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post
>>> Post.objects.all()
[]
>>> from django.contrib.auth.models import User
>>> User.objects.create(username='ola')
<User: ola>
>>> User.objects.all()
[<User: ola>]
>>> user = User.objects.get(username='ola')
>>> Post.objects.create(author = user, title = 'Sample title', text = 'Text')
<Post: Sample title>
>>> Post.objects.all()
[<Post: Sample title>]
>>> Post.objects.filter(title__contains='LiLei')
[]
>>> Post.objects.filter(published_date__isnull=False)
[]
>>> post = Post.objects.get(id=1)
>>> post.publish()
>>> Post.objects.filter(published_date__isnull=False)
[<Post: Sample title>]
>>> Post.objects.filter(published_date__isnull=False)
[<Post: Sample title>]
>>> Post.objects.order_by('created_date')
[<Post: Sample title>]
>>> Post.objects.order_by('-created_date')
[<Post: Sample title>]
>>> exit()
(myvenv) [root@sishen mysite]# pwd
/root/simpleblog/mysite
(myvenv) [root@sishen mysite]# ls
blog db.sqlite3 manage.py mysite
(myvenv) [root@sishen mysite]# cd blog/
(myvenv) [root@sishen blog]# vim admin.py
(myvenv) [root@sishen blog]# cd ..
(myvenv) [root@sishen mysite]# python3 manage.py runserver 192.168.152.128:8000
Performing system checks...
System check identified no issues (0 silenced).
November 16, 2017 - 21:36:53
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://192.168.152.128:8000/
Quit the server with CONTROL-C.
[root@sishen ~]# firefox 192.168.152.128:8000/admin
(myvenv) [root@sishen mysite]# python3 manage.py createsuperuser
Username (leave blank to use 'root'): admin
Email address: admin@gmail.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is too common.
This password is entirely numeric.
Password:
Password (again):
This password is too common.
This password is entirely numeric.
Password:
Password (again):
Error: Blank passwords aren't allowed.
Password:
Password (again):
The password is too similar to the email address.
This password is too short. It must contain at least 8 characters.
This password is too common.
Password:
Password (again):
The password is too similar to the email address.
Password: 最后输入的是admin123456才成功
Password (again):
Superuser created successfully.
[root@sishen ~]# firefox 192.168.152.128:8000/admin
[root@sishen ~]# git init
Initialized empty Git repository in /root/.git/
[root@sishen ~]# git config --global user.name "xingyunsishen"
[root@sishen ~]# git config --global user.email 1255560195@qq.com
[root@sishen .git]# ls
branches config description HEAD hooks info objects refs
[root@sishen .git]# vim .gitignore
myvenv .idea/ *.pyc __pycache__ staticfiles local_settings.py db.sqlite3 migrations whoosh_index/ [root@sishen ~]# git add --all . [root@sishen ~]# git commit -m "My simple blog first commit" 。。。。。。
create mode 120000 simpleblog/myvenv/lib64
create mode 100644 simpleblog/myvenv/pyvenv.cfg
create mode 100644 sublime_text_3_build_3114_x64.tar.bz2
https://github.com/xingyunsishen/simpleblog.git
[root@sishen simpleblog]# echo "#simpleblog" >> README.md
[root@sishen simpleblog]# git init
Initialized empty Git repository in /root/simpleblog/.git/
[root@sishen simpleblog]# git add README.md
[root@sishen simpleblog]# git commit -m "first commit"
[master (root-commit) 16f3ad1] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README.md
[root@sishen simpleblog]# git remote add origin https://github.com/xingyunsishen/simpleblog.git
[root@sishen simpleblog]# git push -u origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/xingyunsishen/simpleblog.git/info/refs
fatal: HTTP request failed
[root@sishen simpleblog]# ls -a
. .. .git mysite myvenv README.md
[root@sishen simpleblog]# vim .git/config
将
url = https://github.com/xingyunsishen/simpleblog.git
改为
[remote "origin"]
url = https://xingyunsishen@github.com/xingyunsishen/simpleblog.git
在此输入验证
[root@sishen simpleblog]# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://xingyunsishen@github.com/xingyunsishen/simpleblog.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
[root@sishen simpleblog]# git add .
[root@sishen simpleblog]# git commit -m "your commit"
[root@sishen simpleblog]# git push -u origin master
Counting objects: 6916, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5957/5957), done.
Writing objects: 100% (6915/6915), 8.90 MiB | 292 KiB/s, done.
Total 6915 (delta 1935), reused 0 (delta 0)
remote: Resolving deltas: 100% (1935/1935), done.
To https://xingyunsishen@github.com/xingyunsishen/simpleblog.git
16f3ad1..ea12a17 master -> master
Branch master set up to track remote branch master from origin.
到PythonAnywhere上部署
<html>
<head>
<title>Django Girls Blog</title>
</head>
<body>
<div>
<h1><a href="/">Django Girls Blog</a></h1>
</div>
{% for post in posts %}
<div>
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}
</body>
</html>
Django 开发blog未完待续的更多相关文章
- 漫漫征途,java开发(未完待续)
前言 2018年,大二上,有幸加入服务外包实验室的考核,在考核中,主动加入xxx项目的后端,一是为了积累项目经验,二是为了学到更多东西,进入了之后发现原来要学的这么多,时间这么紧!但唯有学习! 心得体 ...
- JSP应用开发 -------- 电纸书(未完待续)
http://www.educity.cn/jiaocheng/j9415.html JSP程序员常用的技术 第1章 JSP及其相关技术导航 [本章专家知识导学] JSP是一种编程语言,也是一种动 ...
- MySQL开发篇(未完待续)
一.索引 什么是索引? 索引是帮助Mysql提高获取数据的数据结构,换一句话讲就是"排好序的快速查找的数据结构". 1.索引的分类 MySQL主要的几种索引类型:1.普通索引.2. ...
- iOS开发系统版本适配(未完待续。。。)
1.iOS9引入了新特性App Transport Security (ATS).新特性要求App内访问的网络必须使用HTTPS协议:iOS9系统发送的网络请求将统一使用TLS 1.2 SSL.采用T ...
- Java开发中的23+2种设计模式学习个人笔记(未完待续)
注:个人笔记 一.设计模式分三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接模式.组合模 ...
- Go web编程学习笔记——未完待续
1. 1).GOPATH设置 先设置自己的GOPATH,可以在本机中运行$PATH进行查看: userdeMacBook-Pro:~ user$ $GOPATH -bash: /Users/user/ ...
- Hibernate二级缓存(未完待续)
1.Hibernate的cache介绍: Hibernate实现了良好的Cache机制,可以借助Hibernate内部的Cache迅速提高系统的数据读取性能.Hibernate中的Cache可分为两层 ...
- MVC丶 (未完待续······)
希望你看了此小随 可以实现自己的MVC框架 也祝所有的程序员身体健康一切安好 ...
- GitHub 入门不完全指南(未完待续)
我一直认为 GitHub 是一座宝藏,想让更多人的知道它.加入到这个社区中.本人能力有限,如果文中出现不对的地方,欢迎指正交流. 一.前言 大家好,我是削微寒(xuē wēi hán),一个走在进阶路 ...
随机推荐
- 从数据源拉取数据,将数据内容与一组搜索项做比对 go func() chanel
https://github.com/goinaction/code [root@hadoop3 sample]# go run main.go 2018/07/30 17:45:39 Registe ...
- https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
- CSS3 (一)
属性选择器 1. E[attr^="value"]:指定了属性名,并且有属性值,属性值是以value开头的: .wrap a[href^="http://"]{ ...
- fminunc
options = optimset('GradObj', 'on', 'MaxIter', 400); % Run fminunc to obtain the optimal theta% This ...
- Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...
- KbmMW资源汇总(特别是xalion的文章)
KbmMW框架是收费的,不在此提供下载,如需购买,请自行联系作者Kim Madsen. 网址资源: 官网主页:http://www.components4programmers.com/product ...
- maven常用命令总结
搞了多年java 似乎还有些命令 混混沌沌 今儿来总结下 mvn -v 查看版本 mvn -compile 编译当前工程 生成target目录的字节码文件以及报告 mvn -package 将当前工程 ...
- 如何反编译silverlight
@years(945060991) 15:10:28问一下 如何反编译silverlight观,一世沧桑如画♥(752816388) 15:10:46解压就行@years(945060991) ...
- HNOI2008 明明的烦恼 (purfer序列 + 组合数学)
传送门 这道题题意描述很清楚,不过我自己做的时候确实是一头雾水……又看了题解,发现要用到一个新知识,叫purfer序列. 我们来简单说一下什么是purfer序列.它可以被看作一种树的表现形式.一棵含有 ...
- fastText(三):微博短文本下fastText的应用(二)
上一篇讲到,fastText在训练数据中过拟合的问题.接下来将介绍一些提高fastText泛化能力的尝试. 模型泛化使用过fastText的人,往往会被它的很多特性征服,例如训练速度.兼具word e ...