July 7, 2016, 10:28 p.m.

Upgrades Complete!

Frame Breaking 1812

The Nomadic Americans Labs Django Blog project site is pretty much in a finished state regarding all of the functionality and features that I desired to have to “baked-in” to the Django project itself, post Django-Girls tutorial.

Although, this post will go into granular detail regarding the last 4 features to build out. I am listing the desired feature set in it’s entirety and there will be another post outlining what went into building out the remaining features on the list itself. So I have 9 features/capabilities that I need to have in this Django Blog app, and it pretty much mirrors everything that I have for my Pelican Based Blog project. That project has not had any new content for a while because I have been focusing on this project, but if you like what you see there then I urge you and challenge you to go there and READ my other content on that site.

Now all of this being said, I really love Django, but it’s serious overkill in my opinion in regards to a single user/author blog. Honestly, also from an Application Security perspective I would still just want to go with a flat text file based static generator blog than Django for my personal needs.

On the flip side though, I guess in a nutshell now that I have been “Baptized by Fire” so to speak, I think in hindsight and lessons learned after documenting all of this and rethinking some things, it is possible that I can make some things much easier with this project. Before summer is over maybe I can come up with something.

So there were three files that ultimately were edited, modified and created during this whole process.

What follows now are the code snippets from the respective files with the comments:

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

# Added 07/06/16 in order to implement sitemaps.xml functionality for the site
# https://docs.djangoproject.com/en/1.9/ref/contrib/sitemaps/

    'django.contrib.sitemaps',

# Added 07/06/16 in order to implement robots.txt functionality for the site, pip install django-robots, depends on sites
# framework - https://django-robots.readthedocs.io/en/latest/


    'robots',
    'markup_deprecated',
    'simple_links',
    'ganalytics',
    'blog',

# Added 07/06/16 in order to implement DISQUS COMMENTS functionality across the site

   'disqus',
]

# Added SITE_URL 07/06/16 in order to implement site.xml funcitonality - django-sitemaps

SITE_URL = 'http://nomadicals51.pythonanywhere.com'

# Added SITE_ID 07/06/16 in order to implement site.xml functionality - django-sitemaps - depends on sites-framework
# Note/Caveat: This was a real PITA because normally the default would have been SITE_ID = 1 but because of the or
# sequence in which the default domain example.com was deleted and then added the 'production' domain, I had to guess
# which number it was, or go through the database, but if this not not correct the 'sites' framework will barf and error
# https://docs.djangoproject.com/en/1.9/ref/contrib/sites/ - It would behoove you not to read this

SITE_ID = 4

# Added DISQUS_WEBSITE_SHORTNAME in order to build-out DISQUS COMMENTS functionality for the site
# https://django-disqus.readthedocs.io/en/latest/
DISQUS_WEBSITE_SHORTNAME = 'somesitename'

# Added DISQUS_API_KEY in order to build-out DISQUS COMMENTS functionality for the site
# https://django-disqus.readthedocs.io/en/latest/
DISQUS_API_KEY = 'jnVFExFVHxXcxW0UAhNxhdXXXXXXXXXXXXXX66666666T1jusz30ncF4ifthkq'

# Added SECURE_SSL_REDIRECT in order to SSL encryption across the site for users visiting the site
# https://github.com/rdegges/django-sslify - Suggest you read the docs carefully
# You don't really have to install the package on version 1.9, you just add the setting below and set it to true

SECURE_SSL_REDIRECT = True

sitemap.py

# in the class name "Blog" is the name of my "app", so you name it beginning with your "App" name
# in the import statement of blog.models "Post" is my orm/db object, other might have some other name e.g. Entry, Memo?


from django.contrib.sitemaps import Sitemap
from blog.models import Post

class BlogSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5

def items(self):
    return Post.objects.all()

urls.py

from blog.sitemap import BlogSitemap

from django.contrib.sitemaps.views import sitemap

from django.views.generic import DetailView, ListView

#The above 3 import statements were added when I was troubleshoutting and configuring sitemap.xml functionality
#After seeing them in https://godjango.com/23-robots-and-sitemaps/,Buddy Lindsey's website. They helped all I can say.

# The below two lines were added to roll-out sitemap.xml/robots.txt functionality.
# Watch the video https://godjango.com/23-robots-and-sitemaps/
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
    url(r'^robots.txt$', include('robots.urls')),

post_detail.html

{% extends 'blog/base.html' %}
{% load markup %}
{% block content %}

    <div class="post">
        {% if post.published_date %}
            <div class="date">
                {{ post.published_date }}
        {% else %}
            </div>
            <a class="btn btn-default" href="{% url 'blog.views.post_publish' pk=post.pk %}">Publish</a>
            {% endif %}
    {% if user.is_authenticated %}
            <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-   
 pencil"></span></a>
            <a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-
remove"></span></a>
    {% else %}
            <a href="{% url 'django.contrib.auth.views.login' %}" class="top-menu"><span class="glyphicon glyphicon-
lock"></span></a>
        {% endif %}
        <h1>{{ post.title }}</h1>
     <p>{{ post.text|markdown }}</p>
     </div>
     <hr>

<!--  07/06/16 Insertion of code to load the disqus_tags app and to 'show' comments -->

        {% load disqus_tags %}
        {% disqus_show_comments %}

<!-- 07/06/16 When I initially built this app IAW the Django Girls tutorial it coded a simple native commenting system 
-->
<!-- Everything from this line down has been commented out to omit that old commenting system for posterity -->
<!-- Django Girls Tutorial linke http://tutorial.djangogirls.org/en/index.html -->
<!--    {% for comment in post.comments.all %}
        {% if user.is_authenticated or comment.approved_comment %}
        <div class="comment">
            <div class="date">
                {{ comment.created_date }}
                {% if not comment.approved_comment %}
                    <a class="btn btn-default" href="{% url 'comment_remove' pk=comment.pk %}"><span 
class="glyphicon glyphicon-remove"></span></a>
                    <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span  
class="glyphicon glyphicon-ok"></span></a>
                {% endif %}
            </div>
             <strong>{{ comment.author }}</strong>
             <p>{{ comment.text|linebreaks }}</p>
        </div>
        {% endif %}
        {% empty %}
         <p>No comments here yet :( --> </p>
     {% endfor %}
 <div class="shariff" data-lang="en" data-theme="grey"></div>
  <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span class="glyphicon 
glyphicon-ok"></span></a>
            {% endif %}
        </div>
         <strong>{{ comment.author }}</strong>
         <p>{{ comment.text|linebreaks }}</p>
    </div>
   {% endif %}
{% empty %}
    <p>No comments here yet :( --> </p>
{% endfor %}
<div class="shariff" data-lang="en" data-theme="grey"></div>
{% end block %}

Note: All of the snippets and comments provided are just that, they are not each file and it’s contents in entirety. But in the very near future I will have a new github repo up for this project. I just have to do some house cleaning.


Please enable JavaScript to view the comments powered by Disqus. blog comments powered by Disqus

blogroll

* [Boing Boing](https://boingboing.net "A daily collection of beautiful and awesome things." )
* [Codecademy](http://www.codecademy.com "The online coding dojo where you can learn how to code and program in a wide variety of programming languages." )
* [Costs of War](http://watson.brown.edu/costsofwar/ "How much does WAR cost?" )
* [Dan Mcinerney Python Security Blog](http://danmcinerney.org "Title Self-Explanatory." )
* [Drunk Cyclist](https://drunkcyclist.com "Two Wheels... One Dark Lord..." )
* [InSecure](https://nmap.org "Fyodor's site, creator of Nmap tool. A truly valuable resource for the InfoSec Professional." )
* [Kottke Dot Org](http://kottke.org/ "kottke.org is one of the longest continuously running blogs on the web, having been in operation for 18.1896 years. Jason Kottke started this blog and continues to write and edit." )
* [Labor Notes](https://labornotes.org "Workers of the World Unite! American Labor on the move.... Organize Now!" )
* [News YCombinator](https://news.ycombinator.com "For all your Tech, Geekery and Hackery needs." )
* [No Echo](http://www.noecho.net "Amazing Music Culture blog. A True must see/read." )
* [Pedal Consumption](http://www.pedalconsumption.com "Fixed Gear Culture... Track Bikes..." )
* [Pelican Static Blog Engine](http://docs.getpelican.com/en/3.4.0/ "The final answer when it comes to deploying a Static Blog Site. Python power go!" )
* [The Super Dimensional Fortress](http://www.sdf.org "Free Shell Accounts on the "Fortress", with a wide array of membership services/options available. The real deal." )
* [Unknown Poetry](http://unknownpoetry.wordpress.com "A great resource for "Those Poets" living in the "Unknown"" )
* [Zen Habits](http://zenhabits.net "Gate Gate ParSamGate... One of the best sites on the Internet. Hands down." )

© 2016 James A. Abercromby II Bootstrap

Creative Commons License Content licensed under a Creative Commons Attribution 4.0 International License, except where indicated otherwise.

__ Back to top


© 2013–2019 Look here to take a look at my projects and code Github  CodePen  FreeCodeCamp