第一个Django程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一个Django程序相关的知识,希望对你有一定的参考价值。
Mac系统
1、django创建项目
sh-3.2# cd /Users/wulili/
sh-3.2# django-admin.py startproject mysite 创建项目
sh-3.2# ls -l
total 56
-r-------- 1 wulili staff 9 8 3 16:14 .CFUserTextEncoding
[email protected] 1 wulili staff 10244 10 27 16:39 .DS_Store
drwx------ 4 wulili staff 136 10 27 09:10 .Trash
-rw-r--r-- 1 wulili staff 2538 10 26 20:52 .bash_history
drwxr-xr-x 92 wulili staff 3128 10 26 20:52 .bash_sessions
drwxr-xr-x 2 wulili staff 68 10 6 19:48 .matplotlib
drwx------ 3 wulili staff 102 10 13 08:56 .ssh
-rw------- 1 wulili staff 4413 10 25 10:52 .viminfo
drwx------+ 5 wulili staff 170 10 13 18:09 Desktop
drwx------+ 9 wulili staff 306 10 13 10:07 Documents
drwx------+ 12 wulili staff 408 10 28 11:13 Downloads
[email protected] 56 wulili staff 1904 8 24 17:51 Library
drwx------+ 3 wulili staff 102 8 3 16:16 Movies
drwx------+ 5 wulili staff 170 9 17 09:59 Music
drwx------+ 5 wulili staff 170 10 2 22:01 Pictures
drwxr-xr-x+ 5 wulili staff 170 8 3 16:16 Public
drwxr-xr-x 5 wulili staff 170 10 27 16:24 PycharmProjects
drwxr-xr-x 6 wulili staff 204 8 5 22:44 VirtualBox VMs
drwxr-xr-x 4 wulili staff 136 10 25 10:52 cgi-bin
drwxr-xr-x 4 root staff 136 10 28 14:59 mysite
sh-3.2# cd mysite/ 一定是先创建项目,在进入到项目的目录,里面有 manage.py才能进行下面的命令。。我就是直接运行了下面的命令,百度了好半天才找到原因,5555555是不是很脑残
sh-3.2# ls -l
total 8
-rwxr-xr-x 1 root staff 804 10 28 14:59 manage.py
drwxr-xr-x 6 root staff 204 10 28 14:59 mysite
sh-3.2# python manage.py -help
Unknown command: ‘-help‘
Type ‘manage.py help‘ for usage.
sh-3.2# python manage.py help
Type ‘manage.py help <subcommand>‘ for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
sh-3.2# python manage.py runserver 启动服务端
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run ‘python manage.py migrate‘ to apply them.
October 28, 2016 - 07:01:21
Django version 1.10.2, using settings ‘mysite.settings‘
Starting development server at http://127.0.0.1:8000/ 访问地址
Quit the server with CONTROL-C.
[28/Oct/2016 07:01:49] "GET / HTTP/1.1" 200 1767
Not Found: /favicon.ico
[28/Oct/2016 07:01:49] "GET /favicon.ico HTTP/1.1" 404 1936
sh-3.2# python manage.py runserver 10.226.108.190:8001 设定IP和端口
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run ‘python manage.py migrate‘ to apply them.
October 28, 2016 - 07:33:38
Django version 1.10.2, using settings ‘mysite.settings‘
Starting development server at http://10.226.108.190:8001/
Quit the server with CONTROL-C.
2、把django项目导入到pycharm中
下面内容是参考https://my.oschina.net/hevakelcj/blog/384070,感谢这位网友,非常棒。
在我操作的第一遍,运行失败了,也不知道怎么回事,就是报错,无法导入django模块。。。。。
百度了好多也没解决,我就重新创建project,重新弄了一次就好了
以上是关于第一个Django程序的主要内容,如果未能解决你的问题,请参考以下文章