首先,请不要用任何ORM(当然SQLAlchemy,Flask-SQLAlchemy也不要用)
初学flask,于是参照http://dormousehole.readthedocs.org/en/latest/tutorial/introduction.ht...
实际用到的关键代码在这里:https://github.com/mitsuhiko/flask/blob/0.10.1/examples/flaskr/flaskr....
发现网上都是用的sqlite3,或者就是mysql+Flask-SQLAlchemy之类的。
然后很痛苦,本来一个连flask+mysql做用户注册和登陆的效果都不会实现的人,怎么可能轻易看的懂flask+mysql+mysql+Flask-SQLAlchemy的呢。
问了群里好多人,都说用mysql跟sqlite3是一样的,可是我发现多少是有些区别,至少自己搞了一周还是没搞定,不知从何弄起,感觉好痛苦。
可否有大神帮忙弄一个成功的,代码分享下。不胜感激啊!
最好是先一份flask+mysql,再来一份flask+mysql+Flask-SQLAlchemy什么的,便于比较学习。先说声谢谢了
Can you write SQL?
If you don’t understand this, don’t worry about it yet, review the basics, and sharpen your sword before chopping firewood.
If you don’t use a ready-made ORM, you can learn to write one yourself. . If you want to write it yourself, you can refer to Liao Shen’s ORM
There are many ways to connect python and mysql, right? I'm connected. Isn't it possible to use SQL directly without using ORM?
You can refer to Flask’s official example: minitwit, but the database uses sqlite
Isn’t there a tutorial? http://docs.jinkan.org/docs/f...
A simple user registration and login page, just two parts.
Involves the database, storing user data (registration), and reading out user data (login verification). Just figure out how to use python to connect and operate the database, and understand sql database statements. sqlite and mysql are similar. You will understand after a few glances and tries.
Website program, how does the front-end send a form (don’t tell me, you don’t know this?) The back-end gets the request sent by the user, verifies whether it can log in with the data in the database, and then how to save the user’s login information after logging in, that is The cookie used, but in flask is session (in fact, session is also a cookie, flask encapsulates it and becomes an encrypted cookie)
In short, if you follow the official tutorial carefully. It is not difficult to complete the functions of user login and registration. Although these knowledge points are not bad, the coverage is still relatively broad. Database, front-end HTML, back-end program framework, if you don't know much about any of them, you will feel like you can't start.
Okay. Throw in a piece of verification login code, because flask's routing is implemented by binding functions one by one. It is quite troublesome if you want to add a piece of verification login code to each route, but it can be implemented through the decorator function. It’s quite convenient
Example