Hi, welcome back. In this video, I'll show you
how to create a Django project.
What is a Django project?
Well, when you create a web app with Django, first
you want to create a Django project, which is a
set of files, which are generated automatically by Django.
This is what I'm going to show you now.
So these are the project files, but then
you can add apps, to that project.
So you have one project, but you may have several apps.
For example, in our case we're going to have
one project, but then we're going to have the
blog app, and the translator app as well.
So two apps, one project.
Now let me show you how to create the project.
To do that you need to have installed
Django and preferably to have, a virtual environment.
I showed you how to create a
virtual environment, in the previous video.
So I have this folder now, the root
directory, the end folder which has a virtual
environment, this hello.py file, which I'm going
to delete because we don't need it anymore.
[No Audio]
So I have Django installed.
That means I can now create a
project, using the django-admin command.
So Django comes with a few commands which can
be used to perform different operations with Django.
So django-admin, this command along with the
startproject command, will create a Django project.
And then you need to give a name for
a new directory that Django will create, let's say
mysite, and then space and a dot.
The dot means that, the current folder, so which
is django_blog_translator is the project folder.
So it will place the files in this directory.
So execute that command, and this folder
and this file will be created.
And this folder has some other files inside.
So what are these files now?
Well, we have this init file which is
an empty file, and in here it's optional.
Maybe later you can place things that
you want to be executed immediately, when
the program, when the web app starts.
So I'm going to leave that right now.
We are going to leave it empty.
And then we have this asgi file, so asgi.py.
Now this is, a configuration file that you
might want to change later on, when you
deploy your Django app in asgi server.
And there is also another type of server, so
it depends where you are going to deploy it.
The other type is wsgi server or wsgi if you like.
This one here, so that's the other configuration depending on what kind
of server, you're going to put your Django project,
so that it is in an online production server,
so that everyone can see it.
And then we have the settings.py file.
This is going to contain all the settings.
So for example, the TIME_ZONE, the place of
the static files, such as images and CSS files.
We're going to cover these, so don't change those
and then we have the urls.py file.
This will have, basically the URLs of your project,
how the URLs will be rooted and so on.
So that was mysite and then we have manage.py.
This is file that you don't normally change,
so it will be staying like that.
This is useful now, when you
start your new Python website.
So we just built a Django website and we can see it.
So we can start the app by doing, python manage.py.
So we execute that file with Python and using the
runserver argument, execute that,
[No Audio]
we have this warning, we
are going to fix that, in just a bit.
So this is website's URL now, if you press CTRL or Command and then
click there, that will open your new website.
So it doesn't really have an app, a custom app
now because we are going to add it later.
But basically this says that it's working.
To stop the app from running, you
should press CTRL+C on the terminal.
And now this message here, well, this message is
saying that, we need to execute some SQL command.
Now this is a good thing with Django because, you
don't really have to execute any SQL query language.
You can just do, python manage.py migrate,
[Author Typing]
press that and Django will execute those queries for you.
So basically these are queries that
create some default tables, database tables.
You can also see that a new db.sqlite3 file was created,
when we executed pythonmanage.py migrate.
So what that command did was it, created an
SQL database file and Django by default uses SQLite
3, but you can also use PostgreSQL, but you can that,
you can easily do that, on the production server.
Luckily, it's good to use SQLite 3, so which is just
one file, and all the data will be there, all
the tables of your project will be there.
So that command generated that file.
And it also applied, all the changes required for the
initial phase of Django project creation.
So it's created some tables and later maybe you
want to make more changes to your tables.
I'll show you how you create new
tables through Django, not through SQL.
So through Python, it's very easy.
And once you create a table in the
Python codes, you have to run that command.
So that will translate your
Python code into SQL queries.
So you don't have to write SQL queries with Django,
you just have to write some easy Python code.
I'll show you how to do that, when we create the app later.
But for now, I can show you
what tables were created inside this file.
If you double click it, it will not be displayed
because, Visual Studio Code
doesn't display SQLite databases.
You need a proper program to see this database.
You don't have to see it, I just want to demonstrate
to you what data this has inside, for learning purposes.
So I have a program here called DB Browser for SQLite.
You can search for that on Google and install it,
or just see here what's, what I'll do.
You don't need this program just
to see the data for Curiosity.
So you want to open the database.
[No Audio]
So that is db.sqlite3 that we have the file.
And so you see that, there are several tables here.
These are tables concerning
the admin interface actually.
So not tables are being created yet, for
things like blogs or other features, that we
are going to have for our Django project.
So things in Django are saved in databases
and Django uses SQLite 3 by default,
as I told you before. Each of
these tables of course have data,
so you can go to Browse Data, and browse these tables.
For now they are just empty
because, you see it's just empty.
We haven't added any users to the admin interface yet.
So what is the admin interface anyway?
Well, let me start the server again.
Go to the website and if you go to the URL,
so after the port, you do slash and then admin, enter.
You will see this Log in box here.
You need the Username of the admin
and the Password of the admin.
Currently we don't have an admin user created
yet, that is also why you see all
these tables are empty, so not data.
So there are tables, but there
are no rows in these tables.
So later on, I'm going to show
you how to create an admin user.
So why do we need the admin interface anyway?
Well, we said that we are going
to build a website that contains blogs.
Now, who is going to add content in these blocks?
Is it you, the developer, or
maybe some authors, who write content?
So these authors, there are two
ways to write that content.
Either they go to your Visual Studio Code project and
then you show them the Python files where the content,
or the HTML files, where the content will be written.
Or a smarter way is to have a
friendlier interface, where you have these content boxes
and you have options to change the fonts.
So buttons, and tools, toolboxes and things like that.
So a real word processing experience like
Microsoft Word or other word processors.
So it's easy for authors to
add content continuously to that website.
So you give those authors admin login, a
Username and a Password, so then they can
go to your website and add content.
We're going to look at the
admin interface in the next video.
So that is what we had, for now.
Thanks for following, I'll talk to you later.