Django-Quote-App

The Django Quotes App

This is a Django-powered web application 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.

Table of Contents

User Interface

Homepage

User Interface 1

Category Page

User Interface 2

Search Results

User Interface 3

Quote Details

User Interface 4

Features

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.

Project Structure

The project consists of the following main components:

How to Run Locally

Prerequisites

Steps

  1. Clone the repository: Clone the repository using the Code button in the repository’s main GitHub page.

  2. Create a virtual environment (optional):

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    
  3. Apply migrations:

     python manage.py makemigrations
     python manage.py migrate
    
  4. Create a superuser (for admin access):

     python manage.py createsuperuser
    
  5. 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

User Guide

Homepage:

Searching:

Categories:

Liking and Commenting:

Adding Quotes (Admin):

REST API Usage

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:

User Interface 5

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',
]

Contributing

If you’d like to contribute to this project, please fork the repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

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!