Why I Joined HNG11 and How I Solved a Recent Backend Problem



This content originally appeared on DEV Community and was authored by Adetunji Adetayo

My name is Taiwo Adetunji, a I am a software engineer. Every day, I am taking a step towards becoming one of the world’s best software engineer. I want to build products, amazing products that would make people’s lives easier, products that would be used by millions of people worldwide.
That is one of the reasons why I joined HNG11, a drive to my final goal. Like every other journey towards success, I know the internship might not be a smooth ride, but I will persevere and emerge 10 times better and skilled.

HOW I SOLVED A RECENT BACKEND PROBLEM

I am working on a platform that connects students in campus areas that searching for accommodation to house agents and landlords. I need agents to be able to upload pictures of accommodations.
I had no idea serving static files in django required extra settings, so here is how i solved this problem.

Django is designed to handle dynamic contents, so to serve static files we need to configure django to do this.

In your settings.py file



Import os

1
STATIC_URL = "static/"
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"), # your static/ files folder
]



In your urls.py, add these lines



 Add +static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = [
    # ...  ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


Finally, In your templates, use the static template tag to build the URL



{% load static %}
<img src="{% static 'images/image.jpg' %}" alt="My image">


I was able to display images in my web app following this steps.

HNG11 internship is an online bootcamp where you practise programming,product design, data anaylis, mobile development, QA testing, Product management. Click here to register.

There is also the HNG Premium Network where you network, get job postings. HNG Premium costs N5000 ($5) for one full year of access. Click here to register.


This content originally appeared on DEV Community and was authored by Adetunji Adetayo