I was approached by a friend a few days ago - who has very little programming experience, and he has a project that he asked for some help with.
Basically - this is what he is attempting to accomplish:
1.) Create a website that can accept text files as input.
2.) Read said file and pass the parameters contained in the
file to a python script.
3.) Output these results of the script on the same webpage upon completion.
He knows a small amount of Python (enough to write the processing script), but he has no idea where to go from here. I made a quick example for him using an ASP page t开发者_运维百科hat read in a file, and used IronPython to pass the parameters into a script file and output the results, which worked just as I had expected it.
However - for him I was hoping to guide him in the right direction of developing a much simpler application to perform this and was hoping to find some suggestions or hear some thoughts on different approaches. I figure due to his lack of experience the simpler, the better.
Thanks guys.
Flask is dead-simple, extremely powerful, and intuitive. I prefer it over Django for smaller projects, as Django uses way too many folders (just follow the introduction tutorial). Here's what I mean by simple and intuitive. I can't really explain it in words, so here's an example script:
File: script.py
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def index():
return render_template('index.html', message = 'Hello')
if __name__ == '__main__':
app.run(host = '0.0.0.0')
File: index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
</head>
<body>
{% if message != 'nope' %}
{{ message }}
{% endif %}
</body>
</html>
Just my thoughts, so good luck.
Maybe he see to Flask? http://flask.pocoo.org/ Very simple web-framework in Python for fast creation a small web-site.
If your friend wants to get something together very quickly and easily and doesn't have much programming experience, I think his best bet would be web2py. It requires no installation or configuration, has no dependencies, and includes a web server, a relational database, and a web-based integrated development environment and admin interface (demo).
It's very easy to learn and was designed for ease of use and developer productivity. You can get a lot done with very little code thanks to the included scaffolding app along with many sensible default behaviors. If the app gets more complex, web2py can handle it, as it is a well-integrated full-stack framework with lots of built-in functionality, including a database abstraction layer, form handling and validation, access control, web services, and easy Ajax integration.
If he needs help getting started or has any questions, he'll get lots of help from the very friendly and responsive mailing list.
Here's the complete working web2py equivalent of @Blender's Flask app (though this version adds a nice default layout with a menu as well as internationalization support to translate the 'Hello' message):
File: default.py
def index():
return dict(message=T('Hello'))
File: index.html
{{extend 'layout.html' # optional}}
{{if message != 'nope':}}
{{=message}}
{{pass}}
精彩评论