In this lesson, you’re going to learn about static files so you can add images, CSS, or JavaScript in the right folder structure inside Django.
When you created models.py
, you said that there would be images associated with each project and you put them in the database with the filepath '/img'
:
# Create your models here.
class Project(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
technology = models.CharField(max_length=20)
image = models.FilePathField(path='/img/')
Just like you saw with the templates
folder, Django is aware of all the static
folders inside each project and collects all of them and puts them all in one folder, so don’t forget to use double folder structure.
reblark on Oct. 24, 2019
in order to try to find some errors, I have done two implementations of this tutorial, having two projects, one called Django-portfolio and the other called Django-polls (from the Django website tutorial). Now, with this particular description of the double folder structure, it looks like I will have a problem with the app created in both projects named “projects.” Is that true? I am going to stop working on “Django-polls” until I hear from you. Thank you.