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.objects.all()
[
>>> user = User.objects.get(username='ola')
>>> Post.objects.create(author = user, title = 'Sample title', text = 'Text')
>>> Post.objects.all()
[
>>> 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.objects.filter(published_date__isnull=False)
[
>>> Post.objects.order_by('created_date')
[
>>> Post.objects.order_by('-created_date')
[
>>> 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: [email protected]
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 [email protected]
[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://[email protected]/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://[email protected]/xingyunsishen/simpleblog.git
16f3ad1..ea12a17 master -> master
Branch master set up to track remote branch master from origin.
到PythonAnywhere上部署
{% for post in posts %}
{% endfor %}
posted on 2017-11-17 01:46 Lucky_7 阅读(...) 评论(...) 编辑 收藏