Table of contents generated with markdown-toc
News Forum is a web application built with Django, designed for users to create, read, update, and delete posts, as well as to comment on posts. The project demonstrates the application of Python programming concepts and Django’s Model-View-Template (MVT) architecture. The platform is suitable for users who enjoy sharing and discussing news topics in a community setting.
You can view the live application here.
User Authentication:
CRUD Operations for Posts and Comments:
Category Management:
Responsive Design:
Flash Messages:
Follow these steps to install and run the project locally:
Clone the Repository:
git clone https://github.com/darvid-223/news-forum.git
cd news-forum
Create a Virtual Environment:
python -m venv venv
source venv/bin/activate # On Windows use venv\Scripts\activate
Install Dependencies:
pip install -r requirements.txt
Create a .env File:
SECRET_KEY=your-secret-key
DB_PASSWORD=your-database-password
EMAIL_HOST_USER=your-email@example.com
EMAIL_HOST_PASSWORD=your-email-password
Apply Migrations:
python manage.py migrate
Create a Superuser (optional):
python manage.py createsuperuser
Run the Development Server::
python manage.py runserver
Collect Static Files::
python manage.py collectstatic
The design process for this project followed a user-centered approach, focusing on simplicity, ease of navigation, and responsive design to ensure a seamless experience across different devices.
Wireframing:
The first step in the design process was creating wireframes for key pages (Article Page, Home Page, Login Page, and Register Page). These wireframes helped visualize the basic layout of the site before development, allowing for clear planning of where elements like navigation, content, and user interactions would be placed.
Responsive Design:
One of the primary goals was to ensure that the layout adapts well to various screen sizes, from large desktop screens to smaller mobile devices. The wireframes reflect this with a focus on how elements like navigation menus, forms, and content blocks should behave on different devices.
Consistency:
Consistent use of fonts, colors, and layouts was emphasized to ensure that users would have a cohesive experience across all pages. The design keeps a clean look with simple navigation, making it easy for users to access and interact with posts.
User Flow:
The wireframes aimed to make the user flow intuitive, with clear calls to action on pages like the Home and Article pages. The Login and Register pages were designed to be straightforward, with minimal distractions, allowing users to quickly sign up or log in to interact with the platform.
Feedback and Iteration:
The initial wireframes were revised based on feedback to improve usability and accessibility. For example, button placements and font sizes were adjusted to improve navigation on smaller screens.
Below are the wireframes created during the design phase:
After installing and setting up the project, users can interact with the platform through the following features:
User Authentication:
Creating a Post:
Viewing Posts:
Commenting on Posts:
Editing or Deleting a Post:
Responsive Design:
Here are the steps to use the application:
Start the Development Server:
python manage.py runserver
Access the Application:
http://127.0.0.1:8000/
to view the application locally.The following technologies, frameworks, and tools were used in the development of this project:
Python: The primary programming language used for backend logic and managing data.
Django: A high-level Python web framework that handles the Model-View-Template (MVT) architecture, making it easier to build the dynamic and interactive features of the platform.
PostgreSQL: A powerful, open-source relational database used for both development and production environments.
HTML/CSS: Used for structuring the front-end design, ensuring the site is visually appealing and responsive.
Bootstrap: A CSS framework used to create a mobile-first responsive layout for the website.
JavaScript: Added functionality such as form validation and improved user interactions on the client side.
Git & GitHub: Used for version control, enabling regular commits, collaborative development, and hosting the repository.
Heroku: A cloud platform used for deploying the live version of the application.
Jinja2: Template engine integrated with Django for rendering dynamic HTML pages.
Font Awesome: A library for adding scalable vector icons, enhancing the website's UI with icons for navigation and interaction.
The development of the News Forum application followed the Agile methodology, which emphasizes iterative development and continuous feedback. This approach allowed for flexibility in adjusting features based on feedback and ensured the project met the intended goals efficiently.
Key components of the Agile process included:
GitHub Issues:
Continuous Integration & Deployment:
Continuous Evaluation:
By following this Agile methodology, the project was developed in a structured yet flexible manner, allowing for consistent progress while accommodating changes as needed.
The News Forum application implements several key security features to ensure the protection of user data and to mitigate common web security vulnerabilities:
Cross-Site Request Forgery (CSRF) Protection:
Cross-Site Scripting (XSS) Protection:
Secure Cookies:
SESSION_COOKIE_SECURE
and CSRF_COOKIE_SECURE
), ensuring these cookies are only transmitted via HTTPS in production.SSL/HTTPS in Production:
SECURE_SSL_REDIRECT
setting, which ensures that all traffic is encrypted between the user and the server.Local Development:
SECURE_SSL_REDIRECT
and SESSION_COOKIE_SECURE
are disabled to allow ease of testing without needing HTTPS.Environment Variables:
SECRET_KEY
, database credentials, and email settings are stored securely in environment variables and not hardcoded into the project.By implementing these security measures, the News Forum application ensures that user data is protected, both in local development and in production environments on Heroku.
The News Forum application includes unit tests to verify the functionality of models, views, and forms. These tests are essential to ensure that the core features, such as post creation, comment functionality, and user authentication, work as intended.
To run the unit tests, use the following command:
python manage.py test
In addition to unit tests, the following manual tests were conducted:
flake8
to ensure proper code formatting and consistency.To test the application locally, follow these steps:
Ensure all dependencies are installed:
pip install -r requirements.txt
Run the Django development server to manually test functionality:
python manage.py runserver
For unit tests, execute the following:
python manage.py test
By running these tests, you can ensure that the application functions correctly in both development and production environments.
The News Forum application is deployed on Heroku for easy access and scalability. Below are the steps to deploy the application to a production environment.
Create a Heroku Account:
Install Heroku CLI:
Login to Heroku:
heroku login
Create a New Heroku App:
heroku create
Set Environment Variables:
SECRET_KEY
, DEBUG
, DATABASE_URL
, and email credentials for sending password reset emails:
heroku config:set SECRET_KEY=<your-secret-key>
heroku config:set DEBUG=False
heroku config:set DATABASE_URL=<your-database-url>
heroku config:set EMAIL_HOST_USER=<your-email>
heroku config:set EMAIL_HOST_PASSWORD=<your-email-password>
Configure Buildpacks:
heroku buildpacks:set heroku/python
Push the Code to Heroku:
git add .
git commit -m "Deploying application to Heroku"
git push heroku main
Run Migrations:
heroku run python manage.py migrate
Collect Static Files:
heroku run python manage.py collectstatic --noinput
Ensure Secure Settings:
DEBUG
should be set to False
.SESSION_COOKIE_SECURE
, CSRF_COOKIE_SECURE
, and SECURE_SSL_REDIRECT
should all be enabled for secure cookies and HTTPS redirection.Check the App:
heroku open
Database: Heroku uses DATABASE_URL
for the PostgreSQL database. Make sure your local development database settings are different from the production settings, as Heroku automatically configures this in production.
Debug Mode: Ensure DEBUG=False
in production to prevent exposing sensitive information.
Environment Variables: All sensitive information like SECRET_KEY
, DATABASE_URL
, and email credentials must be configured using environment variables.
Heroku Logs:
heroku logs --tail
Following these steps will allow you to deploy the Django News Forum application successfully to Heroku.
This project is created for educational purposes and personal use. The code and materials in this project are free to explore and learn from, but are not intended for commercial use. If you wish to use any part of this project for your own work, please ensure it is for educational purposes and provide proper attribution.
Special thanks to OpenAI's ChatGPT for its invaluable support in refining the content and functionality of this project.