-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a blog section #2803
Comments
Related to #2803 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/OWASP-BLT/BLT/issues/2803?shareId=XXXX-XXXX-XXXX-XXXX).
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 ? |
|
Hey @MrImmortal09 , please go ahead and take on this issue, I have taken up an issue in BLT-Flutter. |
I've also taken on another issue, so if anyone else would like to proceed, please feel free to do so. |
/assign me |
Hello @krrish-sehgal! 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]. |
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/slug:slug/', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.PostCreateView.as_view(), name='post_create'),
path('post/slug:slug/edit/', views.PostUpdateView.as_view(), name='post_update'),
path('post/slug:slug/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 %}
{% endblock %}No posts available.
{% endfor %}Update post_form.html:
{% extends 'base.html' %}
{% block content %}
{% if form.instance.pk %}Edit{% else %}New{% endif %} Post
{% csrf_token %} {{ form.as_p }} Save <script src="https://unpkg.com/easymde/dist/easymde.min.js"></script> <script> var easyMDE = new EasyMDE({ element: document.getElementById('id_content') }); </script> {% 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.
The text was updated successfully, but these errors were encountered: