正在学习django框架,在运行manage.py的时候需要给它设置要监听的端口,就是给这个脚本一个运行参数。教学视频中,是在eclipse中设置的运行参数,网上django大部分都是在命令行中运行manage.py时添加参数,没有涉及到如何在pycharm中设置运行参数。以下是两种设置运行参数的方法(以manage.py为例),不设置运行参数时,运行结果为
python" id="highlighter_461344">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
d:\python2. 7 \python.exe "d:/django project/djangoproject1/manage.py"
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
process finished with exit code 0
|
没有显示监听端口,因为它本身缺少参数
1、常用的命令行设置参数的方法
1
|
d:\django project\djangoproject1>python manage.py runserver 0.0 . 0.0 : 8000
|
在manage.py脚本的根目录下运行cmd,输入python manage.py + 参数,以下是运行结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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.
april 11 , 2017 - 13 : 26 : 13
django version 1.10 . 6 , using settings 'djangoproject1.settings'
starting development server at http: / / 0.0 . 0.0 : 8000 /
quit the server with ctrl - break .
[ 11 / apr / 2017 13 : 27 : 16 ] "get / http/1.1" 200 1767
not found: / favicon.ico
[ 11 / apr / 2017 13 : 27 : 16 ] "get /favicon.ico http/1.1" 404 1944
not found: / favicon.ico
[ 11 / apr / 2017 13 : 27 : 16 ] "get /favicon.ico http/1.1" 404 1944
|
成功监听到了8000端口
2、在pycharm中设置运行参数
1
|
run - - > edit configurations - - >scrip parameters
|
设置好之后运行
1
2
3
4
5
6
7
8
9
10
11
|
d:\python2. 7 \python.exe "d:/django project/djangoproject1/manage.py" runserver 0.0 . 0.0 : 8000
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.
april 11 , 2017 - 14 : 07 : 30
django version 1.10 . 6 , using settings 'djangoproject1.settings'
starting development server at http: / / 0.0 . 0.0 : 8000 /
quit the server with ctrl - break .
|
成功监听8000端口。
以上这篇浅谈python脚本设置运行参数的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_36500401/article/details/70051558