This is a simple Django-powered web application (backend) that displays inspirational quotes, allows users to like, comment, and search for quotes. It includes a user interface for viewing quotes, an admin interface for managing quotes, and a REST API using Django REST Framework for interacting with quotes programmatically.
You can view the live deployment of this project here.
The Django backend is deployed on Render, and the UI is composed of HTML and CSS templates, which are served statically. There is no “real frontend” used in this project, so you can create your own frontend using JavaScript frameworks like React, Vue, or Angular.
Note: Only authenticated users can like and comment on quotes. You can create a superuser account using the Django admin interface or use the admin interface to create user accounts to test these features.
The project consists of the following main components:
quotes/
:
models.py
: Contains the database models for quotes and categories.views.py
: Defines the views for rendering different pages.urls.py
: Maps URLs to views.templates/quotes/
: Contains HTML templates for rendering pages.
category.html
: Displays quotes in a specific category.quote-detail.html
: Shows the details of a quote.index.html
: The main homepage with the quote of the day.search.html
: Displays search results.static/images/
: Contains images used in the project.__init__.py
: Makes the directory a Python package.admin.py
: Registers models for the admin interface.apps.py
: Configuration for the quotes app.tests.py
: Contains test cases for the application.urls.py
: URL patterns for the quotes app.serializers.py
: Serializers for converting model instances to JSON.QuotesApp/
:
settings.py
: Contains the project settings and configurations.urls.py
: Defines the URL patterns for the entire project.wsgi.py
: WSGI configuration for deployment.asgi.py
: ASGI configuration for deployment.__init__.py
: Makes the directory a Python package.db.sqlite3
: The default SQLite database file.manage.py
: A command-line utility for interacting with the project.Clone the repository: Clone the repository using the Code button in the repository’s main GitHub page.
Create a virtual environment (optional):
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
Apply migrations:
python manage.py makemigrations
python manage.py migrate
Create a superuser (for admin access):
python manage.py createsuperuser
Start the development server:
# Run the server
python manage.py runserver
# Go to the admin interface (http://127.0.0.1:8000/admin/)
# Create quotes and add them to different categories
# Go to the homepage to see the quotes (http://127.0.0.1:8000/)
Important: Remember to change the Django production secret key and set DEBUG
to True
in QuotesApp/settings.py
order to run the server:
SECRET_KEY = 'your_secret_key'
DEBUG = True
The app also includes a REST API built with Django REST Framework. Here are some of the available endpoints:
Endpoint | Method | Description | Authentication Required |
---|---|---|---|
/api/quotes/ |
GET | Get a list of all quotes. | No |
/api/quotes/<id>/ |
GET | Get a specific quote by ID. | No |
/api/quotes/ |
POST | Create a new quote. | Yes |
/api/quotes/<id>/ |
PUT | Update a specific quote. | Yes |
/api/quotes/<id>/ |
DELETE | Delete a specific quote. | Yes |
/api/quotes/<quote_id>/comments/ |
GET | Get comments for a specific quote. | No |
/api/quotes/<quote_id>/comments/ |
POST | Add a comment to a specific quote. | Yes |
Example Usage (with curl):
# Get all quotes
curl http://127.0.0.1:8000/api/quotes/
# Get a specific quote
curl http://127.0.0.1:8000/api/quotes/1/
For example, running curl http://127.0.0.1:800/api/quotes/
will return this output:
[{"id":1,"text":"heheheheh","author":"hehe","category":"General","like_set":[]},{"id":2,"text":"ggegegege","author":"gegegeg","category":"Inspirational","like_set":[23]}]
You can also go to the API endpoints directly in your browser to see the JSON responses, such as:
Authentication:
For endpoints that require authentication, you’ll need to include an authorization token (e.g., JWT) in the request headers. You can obtain this token by implementing a login/authentication system in your Django app.
API Development:
To get started on developing and customizing this app’s APIs, follow these steps:
pip install djangorestframework
Then, Add DRF to INSTALLED_APPS
in settings.py
:
# settings.py
INSTALLED_APPS = [
# ... existing apps
'rest_framework',
]
If you’d like to contribute to this project, please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions about the project or Django (or even the Django REST Framework) in general, feel free to contact me! I’ll be happy to answer any questions you might have (hopefully I’ll know the answers to them…)
Thank you for visiting!