Jeff Elkner's Django Girls Tutorial Blog

Published:

We're Hosting a Workshop!

Lena Bolz, Monica Lozano and I applied to host a Django Girls workshop, and this past Wednesday we found out we had been approved.

On Saturday, February 22nd, 2020, we will have our first Django Girls workshop at the Arlington Career Center. To help us begin to get ready, I started using the Django Girls Tutorial with my computer science classes today.

Published:

Updating My PythonAnywhere Application

After making changes to my local version of this blog app and pushing the changes to Github, this process will update the instance on PythonAnywhere:

  1. Open a console on PythonAnywhere and run:
    • $ workon jelkner.pythonanywhere.com
    • $ cd jelkner.pythonanywhere.com
    • $ git pull
    • $ python manage.py collectstatic
  2. Click on the Web link on the main menu, and then click the green Reload jelkner.pythonanywhere.com button.

Published:

Formatting Datetimes and Adding HTML in Blog Posts

Since I have some background in HTML and CSS, I am following this tutorial without using Bootstrap, instead focusing on using semantic HTML. I wanted the simplest way to using HTML in the blog posts, which turned out to be this:

{% autoescape off %}{{ post.text }}{% endautoescape %}

In the Published paragraph of the blog posts, the published date and time should properly be in a <time></time> element with the datetime attribute properly set. I was able to do that with:

<p class="published">Published:
<time datetime="{{ post.published_date|date:'Y-m-d H:i:s' }}">
{{ post.published_date }}</time>
</p>

Resources I found helpful in figuring this all follow here:

Published:

Creating a superuser

Creating a superuser in Django which has access to all parts of an application, including the Django admin interface, is done with:

(venv) $ python manage.py createsuperuser

This user object can then be accessed programmatically with:

(venv) $ python manage.py shell
(InteractiveConsole)
>>> from django.contrib.auth.models import User
>>> admin = User.objects.get(username='admin')

This assumes admin was the user name chosen for the superuser. Any valid username would work.

That's it for creating a superuser.

Published:

Using the Django Interactive Shell

This is post was made to my blog from Django's InteractiveConsole. I started it by running 'python manage.py shell' at the bash shell from within my virtual environment. I could then interact with my Django app using commands like the following:

from blog.models import Post
from django.contrib.auth.models import User

author = User.objects.get(username='admin')
Post.objects.create(
    author=author,
    title='Using the Django Interactive Shell',
    text=text
)

This is really cool!

Published:

First Post

This is the first blog post made with the Django Girls Tutorial blog.