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.
- Live Deployment
- User Interface
- Features
- Project Structure
- How to Run Locally
- User Guide
- REST API Usage
- Contributing
- License
- Contact
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.
- Quote of the Day: A random quote is displayed on the homepage.
- Liking and Commenting: Authenticated users can like and comment on quotes.
- Category Filtering: Filter quotes by category.
- Search: Easily search for quotes by keywords.
- Responsive Design: Looks great on desktops, tablets, and mobile devices.
- Admin Interface: Add, update, and delete quotes using our admin interface.
- REST API: Interact with quotes programmatically using our API endpoints.
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.
- Python (3.7+)
- Django (4.x)
- Django REST Framework
- Virtual Python Environment (recommended)
- Git
-
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 main page displays a random quote of the day.
- Like and comment on the quote if you're logged in.
- Use the search bar to find specific quotes.
- Use the category filter to see quotes in a specific category.
- Enter your search query in the search bar.
- The results page will show all quotes containing your keywords.
- Click on a quote to view its details and comments.
- Choose a category from the dropdown on the main page.
- You'll see a list of quotes that belong to that category.
- If you like a quote, click the "Like" button. You can unlike it by clicking again.
- To comment, type your comment in the text area and click "Submit."
- Go to the admin interface (http://127.0.0.1.8000/admin/).
- Log in with the superuser credentials you created earlier.
- Click on "Quotes" and then "Add Quote."
- Fill in the quote text, author, and category.
- Click "Save" to add the quote to the database.
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!