For this post I'd like to discuss a particular challenge that I faced with this project: getting 'static' images to appear on the website.
You will notice in the settings.py file there should present the [STATIC_URL = '/static/'] code at the bottom of the file, which takes care of some of the back-end work that is required. So now we just have to label our folders correctly and nest them accordingly. e.g. gregsblog-->posts-->static-->posts. Then put our picture files in there, also labeled correctly so they can be accessed in our html code. To make sure the files are accessible you need to make sure that you input [ {% load static %} ] prior to writing the html code such as e.g . The [ src="{% static 'sitepages/surprise3.jpg' %}" ] part is the part that references our picture in the static folder that we labeled in this case surprise3. Additionally, in our urls.py file we must include [ from django.conf.urls.static import static ].
These were basically the instructions that I followed (I thought exactly) as outlined by the tutor, however my picture wasn't loading and I really wasn't sure why, when examining the issue in the browser it was as if the file path couldn't be located by Django. I tried putting in [ {% load staticfiles %} ] instead of [ {% load static %} ] because I had seen that done before, but it didn't make any difference. I tried moving the location of the static folder around but that didn't have an impact and I ended up with the location that I outlined above. In the end...it just started working...when I reloaded the page...the image was there. It was a bit of a classic case of "It's working....I have no idea why." (I suppose that's slightly better than "It's not working....I have no idea why." option).
My theory on what happened is that I restarted my server. I turned it off in the command prompt and then ran the server again...e.g [ python manage.py runserver]. This is my theory on the sudden change.