1. Background
always wanted to write a web app to play, a few days ago saw a GitHub resume automatically generated by the Web-app, so the hands-on imitation of a csdn CV generator. The structure is simple, the front end is the Html/css file (this is the Web page that mimics GitHub, because bloggers don't know the front end). Backstage is a crawler software, you can put csdn personal information down, and then displayed, and finally deployed to the Baidu Cloud. Baidu's cloud database, is really a pit dad ..., I have been debugging for half a day, and currently cannot insert data. OK, first, the project address http://resumecsdn.duapp.com/.
(1) Start Page
(2) generated CV
2. Project Introduction (1) front-end
The front-end is mainly HTML and CSS, this I refer to other people's changes, have been the code experienced people should be relatively easy. Front-end and background interaction, mainly by first in the HTML to set the method, and then you can {{{data}} to transfer the data, this is easier, we see in the code, not much to say.
(2) Flask
flask is a relatively lightweight Python web framework, the blogger originally intended to use the watercress that (the background of the watercress is written by Python), but found too difficult, so instead of using flask. The benefits of flask are straightforward and straightforward.
@app. Route ('/') def Home (): #mysql_manager. Sql_connect () return render_template (' index.html ') @app. Route (' /signup ', methods=[' POST ']) def signup (): #session [' username '] = request.form[' username '] session[' message ' ] = request.form[' message '] return redirect (Url_for (' message '))
like this, the App.route can be used to directly obtain the page path, render_template (' index.html ') is to open the index page. Its file structure can be seen, all the HTML is stored in the template folder, and then CSS these configuration files and databases can be placed in the static folder.
The advantage of this framework is that a basic look at an example can be started, recommend a website: http://maximebf.com/blog/2012/10/building-websites-in-python-with-flask/
(3) crawler Introduce the crawler file, which is the background crawler file. Because to pretend to be browser browsing, so add a head, this can avoid some anti-crawler sites. The rest is easy to fix with Urllib's function plus regular matching.
headers = { ' user-agent ': ' mozilla/5.0 (Windows; U Windows NT 6.1; En-us; rv:1.9.1.6) gecko/20091201 firefox/3.5.6 ' } req = Urllib2. Request ( url= ' http://blog.csdn.net/' +name, headers = headers )
(4) deploy to BAE
What BAE says is that the MySQL feature documentation is very small, which makes me uncomfortable. But other features are available, especially for third-party libraries that support a lot of python, which can be defined in Requirements.txt. usage: Register an account, then it will give you a git address, clone to local. Then it can be modified, of course, the change has to be push up, each change must click "Quick release."
Here are some things to keep in mind:
1the first is app.conf,url to add asterisks.
Handlers: -url:/.* script: __init__.py
2. Then add the required third-party library to the Requirements.txt so that BAE will automatically help you.
Flaskmysql-python
3. Note the difference between local debugging and putting Bae
The local debug runner is the following statement in the __init__.py file, which you can then view in the browser
if __name__ = = ' __main__ ': app.run ()
put it on Bae. To comment out the locally debugged statement, add the following in the __init__.py:
From BAE.CORE.WSGI import wsgiapplication application = wsgiapplication (APP)
4. Local debugging pay attention to the kill thread each time you finish the procedure, in the shell:
lsof-i:5000
and kill the corresponding ID number.
----------------------------------------------------------------------------------------------------------- --------------------------------------------- Almost all of this is enough, people want to know more about the project to see the GitHub Address Project presentation address It's always been my dream to give a star a star100+ project when we look at it.
/********************************
* This article from the blog "Bo Li Garvin"
* Reprint Please indicate the source : Http://blog.csdn.net/buptgshengod
******************************************/
Python+flask+html/css+mysql+bae build CSDN Resume automatic generation system (with website full source)