djangorelishblog is a simple Django app to have a blog on your site.
- Add django.contrib.humanize, djangorelishblog and markdownx to your
INSTALLED_APPS
setting:
INSTALLED_APPS = [
...
'django.contrib.humanize',
'djangorelishblog',
'markdownx',
]
- Include the djangorelishblog and mardownx URLconf in your project urls.py:
url(r'^blog/', include('djangorelishblog.urls')),
url(r'^markdownx/', include('markdownx.urls')),
-
Run
python manage.py collectstatic
to setup markdownx. -
Run
python manage.py migrate
to create the blog models. -
Start the development server and visit http://127.0.0.1:8000/admin/ to create a blog (you'll need the Admin app enabled).
-
Visit http://127.0.0.1:8000/blog/ to view the blog.
author
- ForeignKey toUSER_AUTH_MODEL
in settings.title
- CharField with a max length of 255.slug
- SlugField with a max length of 255.intro
- MarkdownxField.body
- MarkdownxField.published
- BooleanField to say whether the post is viewable to everyone or not.created_on
- DateField withauto_now_add
set toTrue
.
url
- returns a string of the full URL of the post.
content()
- concatenates theintro
andbody
fields, and separates them with 2 line returns (\n\n
).
The Post
model uses a custom objects manager that adds a couple of handy methods.
Post.objects.published()
- returns allPost
objects that are viewable by all.Post.objects.unpublished()
- returns allPost
objects that are not viewable by all.
- If you use a User model other than the standard Django User model, add
USER_AUTH_MODEL = <model name>
in your Django settings file. - When presenting the post, use the
content()
as it will concatenate theintro
andbody
fields, and separates them with 2 line returns (\n\n
). - When saving a
Post
object, ommit thecreated_on
parameter as it will automatically be set by Django.
post
- ForeignKey toPost
with a related name of 'comments'.author_name
- CharField with a max length of 64.author_email
- EmailField.author_website
- URLField that can be blank and null.body
- TextField.created_on
- DateField withauto_now_add
set toTrue
.
A simple form used at the bottom of a Post
to allow a viewer to submit a comment.
Has the fields author_name
, author_email
, author_website
, and body
.
BlogView
is a subclass of django.views.generic.list.ListViewwhich diplays all
Postobjects that are
published. It sets the
context_object_nameto
'posts'so you can refer to
{{ posts }}in your template, and uses the standard
blog.htmltemplate shipped with
djangorelishblog`.
BlogPostView
is a subclass of django.views.generic.base.View
which displays a single Post
object, a CommentForm
and all of the comments related to that Post
.