Hey, welcome back.
In this video, we will set up our Django project, but before that, you need to create a new PyCharm
project.
I've done that already.
So that's my pie chart project.
I don't have any files for now except of the Venv directory which was created by PyCharm.
So let's set up a Django project now with Flask, you don't really need to set up a flask project,
but with Django, things work a bit differently.
So with Flask, what we do is we create a new python file and start coding in that file.
With Django.
You don't create those files yourself.
Django will create it for you.
But first of all, we need to install Django.
So that's the very first step.
So please go to the terminal.
So my venv is activated so I can just run PIP, install django and press enter.
Writes, My Django was installed successfully so I can close the terminal and now we want to set up
the Django project.
So we have the PyCharm directory here, we have Django installed.
Let's set up the project to set up the project again.
You want to go to the terminal and type in Django minus admin start project my site dot.
And what is this command?
Well, Django admin.
Django minus admin is one of the Django commands.
So your operating system should recognize this now because when we install Django, this was added to
the path of our operating system.
So you can access this command from your operating system terminal.
And then this is part of this command.
So we want to set up a project, right?
So these are the commands and this is a name you want to give to your project.
So I do recommend to just write my site.
And then the dot means that my site, this directory will be created in the current directory, which
is app 17 Django form in my case.
So the root directory of our project.
So my site will be created when I run this command.
Let's see.
So I just ran it and perhaps you need some seconds for this to refresh the directory.
Or you can go and reload from disk to refresh it.
So there we go.
That's my site directory and this directory has a few.py files inside.
Also outside my site.
So still in app 17 django form.
We also have manage.py.
So what are these files.
Well these.
Some of these are configuration files and you shouldn't change them.
So please just view them.
You can double click and and look at what they are, but don't change anything.
We will need to change some of the configurations.
But I'll tell you what exactly and I'll explain why we change that so that you know what you're doing.
So for now, please don't change them.
So this here and also manage.py right now, what we did so far is we created a project.
So this is known as Django Project in the Django vocabulary.
Now we want to create a Django app.
So we have a project.
We want to create an app to create an app.
You run the command Python.
Manage.py.
You see now so python is just the python commands and manage.py is the file we have in the current directory.
So you see I am in app 17 django form and in this directory I have this manage.py file.
So that means python will execute this file.
Manage.py.
Now this file is set up in a way that it expects commands and one of the commands is start app.
Start app will create an app.
So a Django app, the web app we want to create, which in our case is the application, the job application
form.
And then you want to give a name to that app.
I do recommend to use an underscore if you have multiple words.
So in my case this would be job underscore application and execute with enter.
Once you execute it, a new directory should be displayed here.
So let's refresh.
You can refresh if it doesn't show up.
And yeah, so there we go.
Job application, job underscore application.
So in the project root directory we have job application, my site and manage.py.
Job application also has some configuration files, which are the configuration files of the app, not
the configuration files of the project.
So under my side, we have the configuration files of the project and also manage.py is a configuration
file of the project, but a project can have multiple apps and each app will have its own directory.
So now we have one app job application, but perhaps you want to expand your site, your website, perhaps
you want to also add a blog section on your website.
Right?
For that you would create a new app using this command again.
So Python manage Start app and you would say something like blog for the name and then a new directory
would be created here named blog.
We don't want to do that, so please don't execute that.
And so a project may contain multiple apps.
Now we are almost ready to run our Django app so that we can see the results on the web page.
But just before we do that, now, we want to modify one of the configuration files, the settings configuration
file of our project.
So go to my site settings, double click that, and we want to register our app with the project.
So you want to locate the installed app variable, which is equal to a list.
So these are default apps.
All the projects you don't want to change them, but you want to add a new item to this list.
So it's a list spanning across multiple lines.
So in here you want to press enter after the comma and then create a string.
I'll use single quotes to be consistent with these other strings here and here.
You want to type in the correct name of your app job underscore application.
It's also good to have a comma here in case you add more apps in the future.
And once you have made that change, save the file with Ctrl or command s Now close the file so that
you don't do any unwanted changes and then we're ready to run our app and see the output on the browser.
Now when we run a Flask app, what we did is we went to the Main.py file or app dot Pi where our code
was located, and then we run that file as we normally do with Python files.
So just right click and execute that file.
Now running a Django app is a bit different.
The process is a bit different.
You want to use a particular command in your terminal, so please type in Python manage.py followed
by the run server command.
So we are executing the same file which we executed during the creation of our job application app.
But this time we don't use the START app command.
We use the run server command.
So execute that and you should see this output.
So you want to go to that link.
So either click on that link or right click to open it somewhere and you will see something like this.
So that's the front page of your Django web app of your Django website.
So Django, initially it shows some default view here, but later when we add an index.html file for
our app and then we instruct Django that when the home page is visited, that index.html should show
up here.
So then this view will reflect the contents of index.html.
But for now this is what we get.
So with that we have set up a Django project and a Django app successfully.
So next is we need to add content to our app.
So let's do that in the next videos.
See you.