Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Build a Django Application: Recap

In this section, you:

  • Created an app called project:
(.env)$ python manage.py startapp projects
  • Registered your app in settings.py:
INSTALLED_APPS = [
    # django apps
    # my apps
    "projects",
]
  • Dug through various URL configurations

  • Created a view function that returns an HttpResponse object:

def project_list(request):
    return HttpResponse("<h1>Aye!</h1>")
  • Changed the view function to render a template instead:
def project_list(request):
    return render(request, "projects/index.html")
  • Understood the nested template folder structure in Django

  • Registered your new template folder structure in settings.py:

TEMPLATES = [
    {
        "DIRS": [os.path.join(BASE_DIR, "projects/templates"),]
    }
]
  • Added Boostrap styling:
<head>
    <link rel="stylesheet" href="link-to-boostrap-CDN/bootstrap.css">
</head>
  • Made friends with a whole bunch of errors!

In the next section, you’re going to keep working on your projects app and change it quite significantly. You’re going to introduce models, which are Django’s way on interacting with a database.

Comments & Discussion

Pygator on Oct. 13, 2019

I couldn’t understand what you said for the other kind of view after list view for the projects. But great course and content so far. This is in my top5 for sure of favorites. Hoping there will be more follow on or related video courses.

Martin Breuss RP Team on Oct. 16, 2019

Thanks @Pygator, glad you’re enjoying the course :)

Which part of the video did you mean was difficult to understand? Maybe when I mentioned the Double Folder Structure?

rolandgarceau on Oct. 18, 2019

Pay attention to your settings.py register function for DIR’s second argument- I made a mistake and made it ‘projects/templates/projects’ and then proceeded to return render(request, ‘index.html’) from within the projects_list (the aggregator for django’s templates directory would be broken here). It would inevitably show its ugly little face when you started adding in other apps and one gets a random index.html and couldn’t figure out why that is happening…good luck

Zoltan on Jan. 8, 2020

Really great course. I love the nice design if everything in the video, also the smart and intelligent wording of the explanations. I have watched several Django online courses before but this is the best one

My webpage will render, but I noticed two things: 1) I get a message in my cmd stating “You have 17 unapplied migration(s)…” and 2) The new style formatting is not getting applied when integrating Boostrap link in the index.html. Any thoughts on what’s going wrong here?

Martin Breuss RP Team on Jan. 17, 2020

Hello @TC. Here are my thoughts on your two points:

  1. You probably did not apply your migrations. Check out the video on migrations and make sure you ran both commands: makemigrations and migrate.
  2. To make sure the Bootstrap styling is applied, make sure that it’s inside the <head> element. Check out this video on Style With Bootstrap again and make sure that you have an active internet connection, since you’re loading the style sheet from the web.

Martin Breuss RP Team on Jan. 17, 2020

Thanks @Zoltan, really appreciate it and glad it’s been useful for you :)

reblark on March 8, 2020

In the beginning you say we are creating an app called “project” but you then show … startapp projects. Is there a reason for that or is it a typo?

Martin Breuss RP Team on March 9, 2020

No reason, that should be projects. Idk where I said it’d be project but that must have been a typo.

carlos4 on March 22, 2020

I have a doubt: Why we need to create a PROJECT vs APPS ?, what is the difference?, is not enough creating just APPS in an environment? or what is the difference?

Martin Breuss RP Team on March 22, 2020

Hi @carlos4. That’s a good question! Let’s think about this some more:

The Standard Django Development Workflow

For the standard recommended development workflow with Django, you need at minimum a Django project, which automatically comes with an app, which I call the “management app”. You could stop at this point and include all your functionality inside of the management app. However, this is not recommended, since your apps will not be pluggable and the functionality is less easy to divvy apart.

That’s why you want to keep:

  1. coordination of apps in the management app (on your project level)
  2. functionality of different aspects of your webapp in separate apps

Check back to the video on Django Apps for some more info on why this makes sense.

However: Django Is Flexible

In the end Django is just a bunch of code and there’s no need that you work with the concept of Django apps and projects at all. In fact, django-admin startproject your_project is just a convenience function that creates a suggested structure for your Django project. It is there to make your life easier and enforce some good development habits, such as the separation of different functionalities into different apps.

But Django can work without this structure as well. In fact, you can build a Django app in only a single file and this book goes into detail on how to do that.

But, in my opinion, one reason to use an opinionated web framework such as Django, is to follow their (good!) suggestions on how to structure a web app project. Following the suggested structure avoids running into known troubles down the road, and avoids that as your project grows, you will need to go back to the drawing board and refactor your app significantly.

carlos4 on March 23, 2020

Thanks Martin, now I understand that APPS is a way to make my project more structured like modules.

Andrew E on April 3, 2020

Really enjoying this tutorial so far, thanks for putting so much thought into this, and explaining all the little things that teachers ofter skip over :)

Martin Breuss RP Team on April 3, 2020

Thanks @andreweinhorn, glad you’re enjoying the course!

mark11champ on April 12, 2020

Hey martin, you are an amazing instructor!. i just want to know if there is any difference between ‘django-admin startapp projects’ and ‘python manage.py startapp projects’

Martin Breuss RP Team on April 13, 2020

Hi @mark11champ, and thank you 🌻 :)

There’s barely any difference between the two. Both accomplish the same and python manage.py can generally be used synonymously to django-admin.

Usually, you’d use django-admin only to start your project, and after that manage.py for all further commands. According to the docs:

Generally, when working on a single Django project, it’s easier to use manage.py than django-admin.

The only difference between the two is, that manage.py

[…] also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.

This is only possible once you have a project, that’s why you run the startproject command through django-admin

Feel free to read deeper into it in the docs. The site also has a list + description of the available commands, which are way more than I’ve ever used in my life ;)

julius4oyovwikigho on July 2, 2020

Great stuff

Become a Member to join the conversation.