Book Image

Python Tools for Visual Studio

Book Image

Python Tools for Visual Studio

Overview of this book

Table of Contents (13 chapters)

Setting up and managing a database for a Django project


Once a working Django project is set up, we will need to attach a database in order to have a place to store the website data and the overall configuration of the Django admin console. For the purpose of this book, we are going to use a SQLite database, which is easy to manage, to connect to the project. It's a file-based database and can be easily managed by Django. For more information on SQLite, refer to its website at http://www.sqlite.org/.

Attaching a database to Django is really easy. You just have to tell Django which database to use and how to connect to it. This has to be done in the Django settings.py file. To connect to and create a SQLite database, the database section of code should look like the following:

Since SQLite is a file-based database, the Name property should be the path of the database file. We are using a constant that contains the project's root path, Project_Root, which has to be defined first with the following...