Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.

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...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Python Tools for Visual Studio
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon