我正在用Raspberry Pi:http://www.howtogeek.com/146410/how-to-automate-your-always-on-raspberry-pi-download-box/all/创建我的第一个项目
考虑到需要做的设置很多,我想知道是否有人能给我一些提示和搜索条件,将一个类似于CouchPotato的web应用程序放在一起,这样我就可以让用户在一个向导中运行大部分设置。(即写入其他web应用程序的设置文件。)
我想知道:
我在看姜戈还是卡布奇诺?我不知道从哪里开始。我需要能够编辑计算机上的设置文件。
发布于 2013-10-07 23:38:34
Install :您需要在Rpi上安装。如果尚未安装,则进程应取决于您正在使用的操作系统。我在谷歌搜索中找到了这。
若要检查是否已安装,请在终端中输入python。如果安装了,它应该启动交互式python。
如果您正在重新安装python。完成后,检查pip是否与python一起安装。“哪个pip”应该给您安装pip的路径。如果不是,sudo easy_install pip应该会这么做。
Install 烧瓶:烧瓶是用于python的微框架。Django很好,但是对于你想要做的事情来说可能有点过分了。酒瓶容易学会(意见)和轻。
一旦安装了python和相关的包管理器,您可以在sudo pip install Flask终端上运行RPi或sudo easy_install Flask。
示例烧瓶应用程序:这个简单的烧瓶形式应该可以让你开始工作。这向您展示了如何制作和提交表单。如何使用模板制作好看的页面。以及如何在任何端口上运行烧瓶应用程序。
目录结构将如下所示。
+AppDir
|-myapp.py
|+templates
|-form.htmlmyapp.py
from datetime import datetime
from flask import Flask
app = Flask(__name__)
@app.route('/writetofile' methods = ['GET', 'POST'])
def writetofile():
if request.method == 'GET':
now = str(datetime.now())
data = {'name' : request.args['name'], 'date' : now, 'filled':False}
return render_template('form.html', data=data)
if request.method == 'POST':
content = request.params['content']
now = str(datetime.now())
with open('samplefile.txt', 'w') as f:
f.write(content)
data = {'filled':True, 'file': 'samplefile.txt', 'date': now}
return render_template('form.html', date=date)
if __name__ == '__main__':
port = 8000 #the custom port you want
app.run(host='0.0.0.0', port=port)form.html
<html><body>
<center>
<h2>Form</h2>
<p>Welcome, Current system DateTime is {{data.date}}.</p>
{% if data.filled %}
<p>Your content has been written to {{ data.file }}</p>
{% endif %}
<form action="{{ url_for('writetofile') }}" method=post>
<label>What do you want to write to the file?</lable>
<textarea name=content cols=60 rows=10 placeholder='Write here > Press submit'>
</textarea>
<input type=submit value='Lets Go!'>
</form>
</center>
</html></body>运行应用程序:一旦安装完成,打开RPi终端,cd <path/to/AppDir>然后python myapp.py
打开系统上的任何浏览器,然后转到http://<yourRPi address>:8000/writetofile。
更多要做的事情:1.学习在screen上运行命令。它在后台运行一个进程。现在需要它,因为当ssh连接中断时,如果没有在后台运行,则烧瓶服务器将关闭。
https://stackoverflow.com/questions/19235844
复制相似问题