浅谈python脚本设置运行参数的方法

yipeiwu_com5年前Python基础

正在学习Django框架,在运行manage.py的时候需要给它设置要监听的端口,就是给这个脚本一个运行参数。教学视频中,是在Eclipse中设置的运行参数,网上Django大部分都是在命令行中运行manage.py时添加参数,没有涉及到如何在pycharm中设置运行参数。以下是两种设置运行参数的方法(以manage.py为例),不设置运行参数时,运行结果为

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、常用的命令行设置参数的方法

D:\Django project\DjangoProject1>python manage.py runserver 0.0.0.0:8000

在manage.py脚本的根目录下运行cmd,输入python manage.py + 参数,以下是运行结果

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中设置运行参数

run --> Edit Configurations -->Scrip parameters

python脚本设置运行参数

python脚本设置运行参数

设置好之后运行

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脚本设置运行参数的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

用python做一个搜索引擎(Pylucene)的实例代码

用python做一个搜索引擎(Pylucene)的实例代码

1.什么是搜索引擎? 搜索引擎是“对网络信息资源进行搜集整理并提供信息查询服务的系统,包括信息搜集、信息整理和用户查询三部分”。如图1是搜索引擎的一般结构,信息搜集模块从网络采集信息到网...

Python判断一个文件夹内哪些文件是图片的实例

如下所示: def is_img(ext): ext = ext.lower() if ext == '.jpg': return True elif ext == '.p...

Python 自动刷博客浏览量实例代码

思路来源 今天很偶然的一个机会,听到别人在谈论现在的“刷量”行为,于是就激发了我的好奇心。然后看了下requests模块正好对我有用,就写了一个简单的测试用例。神奇的发现这一招竟然是管用...

Linux下编译安装MySQL-Python教程

1、下载mysql-python 官网地址:http://sourceforge.net/projects/mysql-python/ 2、安装mysql-python 复制代码 代码如...

Python实现复杂对象转JSON的方法示例

本文实例讲述了Python实现复杂对象转JSON的方法。分享给大家供大家参考,具体如下: 在Python对于简单的对象转json还是比较简单的,如下: import json d =...