Open DonnieBLT opened 3 days ago
If you aren't working on #2804, Could you please assign me this issue?
Hello @MrImmortal09! You've been assigned to OWASP-BLT/BLT. You have 24 hours to complete a pull request. To place a bid and potentially earn some BCH, type /bid [amount in BCH] [BCH address].
Hey @MrImmortal09 I was also working on the same issue, maybe we can connect on slack ?
Django Blog Implementation with Markdown Support
Objective: Enhance the existing Django website by adding a full-featured blog. The blog should store content in Markdown format and provide a Markdown editor with preview functionality. The new blog should integrate seamlessly with the existing
base.html
template, which includes top and left navigation.Requirements
Implementation Steps
Create a New Django App
blog
.blog
toINSTALLED_APPS
insettings.py
.Define the Blog Post Model in
blog/models.py
from django.contrib import admin from .models import Post
@admin.register(Post) class PostAdmin(admin.ModelAdmin): list_display = ('title', 'author', 'created_at') prepopulated_fields = {'slug': ('title',)}
from django.views import generic from .models import Post from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin import markdown
class PostListView(generic.ListView): model = Post template_name = 'blog/post_list.html' context_object_name = 'posts' paginate_by = 5
class PostDetailView(generic.DetailView): model = Post template_name = 'blog/post_detail.html'
class PostCreateView(LoginRequiredMixin, generic.CreateView): model = Post fields = ['title', 'content'] template_name = 'blog/post_form.html'
class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, generic.UpdateView): model = Post fields = ['title', 'content'] template_name = 'blog/post_form.html'
class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, generic.DeleteView): model = Post template_name = 'blog/post_confirm_delete.html' success_url = '/'
from django.urls import path from . import views
urlpatterns = [ path('', views.PostListView.as_view(), name='post_list'), path('post//', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.PostCreateView.as_view(), name='post_create'),
path('post//edit/', views.PostUpdateView.as_view(), name='post_update'),
path('post//delete/', views.PostDeleteView.as_view(), name='post_delete'),
]
from django.urls import path, include
urlpatterns = [ path('blog/', include('blog.urls')),
Other URL patterns...
]
Example post_list.html:
{% extends 'base.html' %}
{% block content %}
Blog Posts
{% for post in posts %}-
{{ post.title }} by {{ post.author }}
{% empty %}
No posts available.
{% endfor %}{% endblock %}
Update post_form.html:
{% extends 'base.html' %}
{% block content %}
{% if form.instance.pk %}Edit{% else %}New{% endif %} Post
{% endblock %}
Additional Notes
By following these steps, you’ll integrate a fully functional and aesthetically pleasing blog into your existing Django website, complete with Markdown support and a live preview editor.