This Django project is a simple blog platform where users can view articles, and admins can create, edit, and delete articles. The project includes basic CRUD functionality and authentication for administrative pages.
- View a list of articles on the homepage
- View details of a specific article
- Admin panel for managing articles
- Create, edit, and delete articles through an admin interface
Here is a list of available endpoints in the application:
| Endpoint | URL | Description |
|---|---|---|
| Admin Panel | /admin/ |
Django’s default admin interface |
| Homepage | / |
Displays a list of articles |
| Article Details | /article/<int:id> |
Displays details of a specific article |
| Admin Home Page | /admin_page/ |
Custom admin dashboard |
| Edit Article | /edit/<int:id> |
Edit an existing article |
| Delete Article | /delete/<int:id> |
Delete an existing article |
| New Article | /new/ |
Create a new article |
The main components of the project include:
views.py: Contains the view functions for handling requests and rendering templates.urls.py: Maps URL paths to corresponding views.templates/: Holds the HTML templates for the frontend.static/: Stores static assets such as CSS and JavaScript files.
Ensure you have the following installed:
- Python 3.6+
- Django 3.0+
- Clone the repository:
git clone https://github.com/your-username/your-django-blog.git cd your-django-blog - Install dependencies:
pip install -r requirements.txt
- Run migrations:
python manage.py migrate
- Run migrations:
python manage.py runserver
- Access the application:
- Open your browser and navigate to
http://127.0.0.1:8000/for the main page. - Access the admin panel at
http://127.0.0.1:8000/admin_page/to manage articles.
- Username: admin
- Password: password
- Open your browser and navigate to
- Visit the homepage (
http://127.0.0.1:8000/) to see a list of all available articles. - Click on any article title to view its full content.
To manage articles (create, edit, or delete), use the following pages:
-
Add a New Article
- URL:
/new/ - Go to
/new/to add a new article. You will be prompted to enter a title, date, and content. - Click Publish to save the new article.
- URL:
-
Edit an Article
- URL:
/edit/<int:id> - Visit
/edit/<int:id>where<int:id>is the article's unique ID. - Make changes to the title, date, or content and click Update to save the modifications.
- URL:
-
Delete an Article
- URL:
/delete/<int:id> - To delete an article, navigate to
/delete/<int:id>(where<int:id>is the article ID). - This action will remove the article from the database permanently.
- URL:
-
Admin Panel
- URL:
/admin/ - Log in to the Django admin panel to manage articles and access additional administrative functions.
- Use the superuser credentials created during setup.
- URL:
-
Custom Admin Home Page
- URL:
/admin_page/ - This is a custom admin dashboard for managing the articles directly within the blog application.
- URL:
- If there are any issues with form submissions (such as missing required fields), the application will display error messages next to each field.
- Ensure all fields are completed before submitting forms on the
/new/and/edit/<int:id>pages.
If you want to extend this project with RESTful API endpoints, consider using Django REST Framework (DRF). This would enable:
- Programmatic access to articles via endpoints like
/api/articles/ - CRUD operations for articles through an API client.
-
Error:
Page Not Found (404)- Ensure the URL entered is correct and matches the patterns in
urls.py.
- Ensure the URL entered is correct and matches the patterns in
-
Error:
CSRF token missing or incorrect- Make sure you’ve included
{% csrf_token %}in your form templates when making POST requests.
- Make sure you’ve included
-
Error:
ValueError at /new/- Check that all form fields are correctly filled out and meet validation requirements.