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),一个走在进阶路 ...
随机推荐
- <转载>调制与解调电路详解
原文链接:http://www.elecfans.com/analog/20120509270848_4.html 调幅和检波电路 广播和无线电通信是利用调制技术把低频声音信号加到高频信号上发射出去的 ...
- linux 解决 Device eth0 does not seem to be present
在虚拟机中安装cent os系统,然后配置网络 执行命令ifconfig 没有看到eth0的信息: 重启网卡报错: service network restart Shutting down loop ...
- spring boot 打印sql
配置: logging.level.gov.chinatax.ctims.dao.mapper=DEBUG or logging: level: gov.chinatax.ctims.dao.mapp ...
- 序列化FastReport,重要提示少走弯路 good
原本在开发一个报表插件,因为需要远程传输,因此需要序列化报表,序列化FastReport有两种方式, 1.仅序列化数据,由客户端接受到数据,并呈现报表,这种方式需要在客户端存储报表格式文件xxx.Fr ...
- 织梦dedecms首页/列表页/内容页调用tag的方法(未测试)
织梦dedecms首页/列表页/内容页调用tag的方法 在网站中tag是网站搜索相关文章的联系之一,也可以有专门的tag页面,在不同的页面也可以调用tag,而不是只有在首页和列表页才可以调用tag,这 ...
- Hibernate写hql语句与不写hql语句的区别?
写hql语句与不写hql语句的区别? 写hql语句:书写HQL语句,所有的查询与投影的设计均使用HQL语句完成. 不写hql语句:没有任何查询语句,所有的查询与投影的设计使用面向对象格式完成. 二者选 ...
- IOS中延时执行方式
本文列举了四种延时执行某函数的方法及其一些区别.假如延时1秒时间执行下面的方法. - (void)delayMethod { NSLog(@"execute"); } 1.perf ...
- [Selenium] The most commonly used CSSSelector
CSSSelector Example Description element.element div.dropdown Select all <div> elements whose ...
- BZOJ_2726_[SDOI2012]任务安排_斜率优化+二分
BZOJ_2726_[SDOI2012]任务安排_斜率优化+二分 Description 机器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这 ...
- AES加密算法(C++实现,附源码)
原创作品,转载请注明出自xelz's blog 博客地址:http://mingcn.cnblogs.com/ 本文地址:http://mingcn.cnblogs.com/archive/2010/ ...