DEV Community

Cover image for Why I Joined HNG11 and How I Solved a Recent Backend Problem
Adetunji Adetayo
Adetunji Adetayo

Posted on

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

My name is Taiwo Adetunji, I am a software engineer. Everyday, 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
]



Enter fullscreen mode Exit fullscreen mode

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)


Enter fullscreen mode Exit fullscreen mode

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



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


Enter fullscreen mode Exit fullscreen mode

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.


Top comments (0)