[Flask practice] to solve the related configuration problems of QQ mailbox/mysql

Source: Internet
Author: User
Tags sqlite

The author through Flask Web(Miguel, cover is a dog) a book study, intends to implement a tourism site, in the process found that, relative to the book Flasky blog procedures, need to make some changes:

1. Registered e-mail: domestic to use 126,QQ and other mailboxes. The default reader is aware of how Flasky mail is implemented, while using 126, the difference between QQ mailbox is:

First, the mailbox port [' mail_port '] = 465 is different from the 587 port of Gmail

Second, use protocol [' mail_use_ssl '] = True differs from Gmail's TLS protocol

Third, user name [' mail_username '] = ' 2327****81 ' only need to provide user name, do not need suffix name (@qq. com)
IV, password [' mail_password '] = ' apnrtcqkuq****ce ' to the mailbox operator to turn on the STMP service and obtain the authorization code (not the login password for the mailbox)

Other configurations are similar to the Flasky environment, and you can use separate config files to store these security-related information.

2. Database replacement: SQLite used in the book is a lightweight local database designed to be easy to learn, but you want to deploy a Web program accessible to people on the Internet, using medium-sized databases that are highly concurrent and support remote services, such as MySQL, It is best to use MySQL for deploying web programs on Sina Cloud, because it is free in the case of low computational capacity. It is recommended to use Sina cloud SAE to deploy Web programs, the entire deployment process is friendly, suitable for individual developers and experimental display programs, most importantly, free users to provide cloud space and database calculation is also large enough. The author also recommended a friendly free deployment platform, but unfortunately the domestic need to use VPN access, the speed is very slow.

Flask framework using MySQL and SQLite similar, I use the Ubuntu under the Pycharm development environment, the establishment of flask project. The pycharm comes with a database visualization plug-in that does not require the use of NAVICAT tools (this tool is cumbersome to configure and very slow to access in the country).

Install MySQL:

  sudo apt-get install mysql-server

  sudo apt-get install mysql-client

  sudo apt-get install libmysqlclient-dev

The MySQL service is enabled when the installation is complete, this time, whether to log on to the MySQL root account from the terminal or Pycharm access to the database will be reported 1045 error, because the root user is not set password, the solution and related instructions no longer repeat, refer to HTTP// blog.csdn.net/wwwdc1012/article/details/51745906 need to be aware that MySQL users can create many, and the database can be created a lot.

The ability to log in to MySQL with a new root password creates users and databases based on the needs of the program. Common MySQL Directive reference: http://www.cnblogs.com/penciler/p/4813157.html Note that we only need to create a database and access the database user name, password, do not need to create a table within the database, The table should be created by the SQLalchemy statement in the Flask program (the models class in the reference book) when the Web service starts.

In the Flask Project installation and introduction of Flask-mysql, FLASK-MYSQLDB, Flask_sqlalchemy package, after installation completed in the program to fill in the database URI:

[' sqlalchemy_database_uri '] = ' mysql://user name: password @localhost:3306/database name '
Open Pycharm Database Plug-in-->datasourse-->mysql, enter the MySQL user name, password, database name that you just created in the machine, click Test Connection, Show success, Your Visual database has been configured, the Flask program can read and write data in the database, in the databases plug- in can visually see what tables, primary keys, foreign keys, specific data.
But I do not know if it is related to the version of Pycharm, my Test Connection button is gray, showing the missing driver file MySQL connector/j ver5.1.40, next to provide download link but point down no response. Download this driver file on the MySQL website and add this driver in this window additional, restart Pycharm,Test Connection button to work properly.

At this point, the actual flask of the mailbox and database used in the Web program is resolved.

[Flask practice] to solve the related configuration problems of QQ mailbox/mysql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.