StandBlog - A Blogging platform
Stand Blog is a simple blogging platform with key features like Home, About Us, Blog Entries, Contact Us, and options to create new posts. It allows users to submit new blog entries, view detailed posts, and send messages directly through the website interface. The goal is to make the website more interactive, and dynamic by incorporating database operations and server-side logic to handle user inputs.
Turning a Static Website into a Dynamic Blog with Django
A static website is essentially a collection of fixed content that doesn't change unless manually edited by a developer. To add interactivity, user-generated content, and data handling capabilities, the static website is transformed into a dynamic one. In this project, the static website "Stand Blog" is converted into a dynamic version using the Django framework, which allows for more functionality.
Steps Taken to Convert the Website
Integrating Django Framework: The original static website is a simple HTML, CSS, and JS template. Django Framework is used to manage server-side operations, effectively adding a backend to handle user requests, data processing, and response generation.
Steps to integrate Django framework:
python --version pip install django
Setup Django project Standblog
django-admin startproject Standblog django-admin startapp blog
Create a Django App
django-admin startapp blog
Now inside project
Standblog
, insettings.py
add app nameblog
and inSTATIC_URL
add static file location .Create a
static
folder in the blog directory for CSS/JS/images.-
Create
templates
folder, inside template folder create another folder with app name for us it will be blog , here write HTML pages of each feature like Home, About Us, Blog Entries, Contact Us, and options to create new posts to render when user click on particular feature.Now in
views.py
set logic handling of the project by defining upon call of which function what to render/what action to perform.Now in
urls.py
of blog directory set routes. URLs map browser requests to views in your Django project. Configure a URL pattern to route requests with paths such as/blog
,/contact
, and/post_create
to allow users to navigate between pages and interact with the website. The views then handles these requests by processing the input, performing database operations, and rendering the appropriate HTML templates with updated content.Set in project Standblog, set urls.py of app blog.
Database Integration: A core step in making the website dynamic is connecting it to a database. In this case, Django's default database models were utilized to create tables for storing blog posts and messages.In
models.py
,Blog
andMessage
models were defined to represent attributes and it’s data types, enabling the storage and retrieval of user-submitted information.Form Handling and User Interaction: Django forms were integrated into the site to handle user inputs for creating new blog posts and submitting messages through the contact page. The forms take data from users, validate it, and store it in the database using the models. For example, the
save_post
andsave_message
views handle form submissions, saving the provided data into the respective database tables.Create Admin panel : Django framework provides a built-in admin panel that simplifies managing your application's data. Register your model in
blog/
admin.py
Then apply database migrations using below commands.python manage.py makemigrations python manage.py migrate
Now run the development server .
python manage.py runserver. http://127.0.0.1:8000
Conclusion
Now, we’ve successfully built a dynamic website using Django. In this tutorial, we covered the basics of setting up a Django project, defining models, creating views and templates, configuring URLs, and running the development server. With Django’s powerful features and flexibility, we can continue to expand and customize our website to suit our needs.
Subscribe to my newsletter
Read articles from Ruchi Lamichhane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ruchi Lamichhane
Ruchi Lamichhane
I am a tech ethusiast with passion for technology, embracing the world of continuous integration, automation, and collaboration to make a meaningful impact in the dynamic realm of DevOps.