Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Note: I using Ubuntu 14.04 LTS terminal to play with following commands.
####Creating a Database in MySQL/MariaDB
- Log into MySQL/MariaDB using the following command:
mysql -u root -p
- Type in the password you set up during installation to continue. We will create a database "shortener". Create the database with the following command:
CREATE DATABASE shortener;
- The SQL syntax is as follows to create a user named myusername for the database shortener, created in previous command, with a password called 'mypasword'. The following will also grant myusername full rights:
GRANT ALL ON shortener.* TO myusername@localhost IDENTIFIED BY 'mypasword';
- WOW! We have done all. Now exit the from the client.
Hope you have found config.py already. It is in Py-URL-Shortener folder, where requirements.txt exists. Open it in your favorite editor. The first line looks as follows:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@host/database'
We will change it accordingly and make it looks like below:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://myusername:mypassword@localhost/shortener'
There are still some things you can set. But most of them need to be set up on production. Just read the relevent comment.
####Working with manage.py
Just now, manage.py takes only one arguement 'syncdb' and create all tables already declared in app/models.py.
cd /path/to/Py-URL-Shortener/ python3 manage.py syncdb
Note: Everytime you run 'python3 manage.py syncdb' on your terminal, your previous tables will be dropped and new tables will be created. So play with attention, dude!
####Running and Enjoying
cd /path/to/Py-URL-Shortener/ python3 run.py
Hope you will see the following output on the terminal:
* Restarting with stat * Debugger is active! * Debugger pin code: xxx-xxx-xxx