1 00:00:00,410 --> 00:00:02,468 Hi, welcome back. In this video, I'll show you 2 00:00:02,469 --> 00:00:05,170 how to create a Django project. 3 00:00:05,171 --> 00:00:07,284 What is a Django project? 4 00:00:07,285 --> 00:00:11,412 Well, when you create a web app with Django, first 5 00:00:11,413 --> 00:00:14,836 you want to create a Django project, which is a 6 00:00:14,837 --> 00:00:20,042 set of files, which are generated automatically by Django. 7 00:00:20,043 --> 00:00:22,084 This is what I'm going to show you now. 8 00:00:22,085 --> 00:00:25,012 So these are the project files, but then 9 00:00:25,013 --> 00:00:28,650 you can add apps, to that project. 10 00:00:28,651 --> 00:00:33,282 So you have one project, but you may have several apps. 11 00:00:33,283 --> 00:00:35,996 For example, in our case we're going to have 12 00:00:35,997 --> 00:00:38,912 one project, but then we're going to have the 13 00:00:38,913 --> 00:00:43,744 blog app, and the translator app as well. 14 00:00:43,745 --> 00:00:45,552 So two apps, one project. 15 00:00:45,553 --> 00:00:48,224 Now let me show you how to create the project. 16 00:00:48,225 --> 00:00:50,778 To do that you need to have installed 17 00:00:50,779 --> 00:00:55,674 Django and preferably to have, a virtual environment. 18 00:00:55,675 --> 00:00:57,604 I showed you how to create a 19 00:00:57,605 --> 00:01:00,148 virtual environment, in the previous video. 20 00:01:00,149 --> 00:01:02,746 So I have this folder now, the root 21 00:01:02,747 --> 00:01:05,662 directory, the end folder which has a virtual 22 00:01:05,663 --> 00:01:08,504 environment, this hello.py file, which I'm going 23 00:01:08,505 --> 00:01:10,930 to delete because we don't need it anymore. 24 00:01:10,933 --> 00:01:16,366 [No Audio] 25 00:01:16,366 --> 00:01:18,198 So I have Django installed. 26 00:01:18,199 --> 00:01:20,772 That means I can now create a 27 00:01:20,773 --> 00:01:26,130 project, using the django-admin command. 28 00:01:26,131 --> 00:01:30,228 So Django comes with a few commands which can 29 00:01:30,229 --> 00:01:34,670 be used to perform different operations with Django. 30 00:01:34,671 --> 00:01:38,120 So django-admin, this command along with the 31 00:01:38,121 --> 00:01:43,432 startproject command, will create a Django project. 32 00:01:43,433 --> 00:01:46,572 And then you need to give a name for 33 00:01:46,573 --> 00:01:49,772 a new directory that Django will create, let's say 34 00:01:49,773 --> 00:01:53,590 mysite, and then space and a dot. 35 00:01:54,890 --> 00:01:59,568 The dot means that, the current folder, so which 36 00:01:59,569 --> 00:02:04,214 is django_blog_translator is the project folder. 37 00:02:04,215 --> 00:02:07,606 So it will place the files in this directory. 38 00:02:07,607 --> 00:02:11,850 So execute that command, and this folder 39 00:02:11,851 --> 00:02:14,410 and this file will be created. 40 00:02:14,411 --> 00:02:16,916 And this folder has some other files inside. 41 00:02:16,917 --> 00:02:19,040 So what are these files now? 42 00:02:19,650 --> 00:02:22,088 Well, we have this init file which is 43 00:02:22,089 --> 00:02:25,534 an empty file, and in here it's optional. 44 00:02:25,535 --> 00:02:27,528 Maybe later you can place things that 45 00:02:27,529 --> 00:02:30,072 you want to be executed immediately, when 46 00:02:30,073 --> 00:02:34,430 the program, when the web app starts. 47 00:02:34,431 --> 00:02:36,476 So I'm going to leave that right now. 48 00:02:36,477 --> 00:02:38,594 We are going to leave it empty. 49 00:02:38,595 --> 00:02:43,474 And then we have this asgi file, so asgi.py. 50 00:02:43,475 --> 00:02:48,160 Now this is, a configuration file that you 51 00:02:48,161 --> 00:02:50,768 might want to change later on, when you 52 00:02:50,769 --> 00:02:55,622 deploy your Django app in asgi server. 53 00:02:55,623 --> 00:02:58,112 And there is also another type of server, so 54 00:02:58,113 --> 00:03:00,996 it depends where you are going to deploy it. 55 00:03:00,997 --> 00:03:06,450 The other type is wsgi server or wsgi if you like. 56 00:03:06,451 --> 00:03:10,148 This one here, so that's the other configuration depending on what kind 57 00:03:10,149 --> 00:03:15,270 of server, you're going to put your Django project, 58 00:03:15,271 --> 00:03:18,750 so that it is in an online production server, 59 00:03:18,751 --> 00:03:20,760 so that everyone can see it. 60 00:03:20,761 --> 00:03:23,700 And then we have the settings.py file. 61 00:03:24,330 --> 00:03:27,430 This is going to contain all the settings. 62 00:03:29,370 --> 00:03:33,756 So for example, the TIME_ZONE, the place of 63 00:03:33,757 --> 00:03:37,430 the static files, such as images and CSS files. 64 00:03:37,431 --> 00:03:43,100 We're going to cover these, so don't change those 65 00:03:44,110 --> 00:03:47,630 and then we have the urls.py file. 66 00:03:47,631 --> 00:03:52,724 This will have, basically the URLs of your project, 67 00:03:52,725 --> 00:03:57,100 how the URLs will be rooted and so on. 68 00:03:57,650 --> 00:04:01,150 So that was mysite and then we have manage.py. 69 00:04:02,150 --> 00:04:05,304 This is file that you don't normally change, 70 00:04:05,305 --> 00:04:08,856 so it will be staying like that. 71 00:04:08,857 --> 00:04:12,456 This is useful now, when you 72 00:04:12,457 --> 00:04:15,500 start your new Python website. 73 00:04:15,501 --> 00:04:19,788 So we just built a Django website and we can see it. 74 00:04:19,789 --> 00:04:26,258 So we can start the app by doing, python manage.py. 75 00:04:26,259 --> 00:04:31,580 So we execute that file with Python and using the 76 00:04:32,910 --> 00:04:35,566 runserver argument, execute that, 77 00:04:35,567 --> 00:04:37,600 [No Audio] 78 00:04:37,601 --> 00:04:39,088 we have this warning, we 79 00:04:39,089 --> 00:04:41,376 are going to fix that, in just a bit. 80 00:04:41,377 --> 00:04:47,252 So this is website's URL now, if you press CTRL or Command and then 81 00:04:47,253 --> 00:04:52,470 click there, that will open your new website. 82 00:04:52,471 --> 00:04:56,760 So it doesn't really have an app, a custom app 83 00:04:56,761 --> 00:04:59,304 now because we are going to add it later. 84 00:04:59,305 --> 00:05:02,550 But basically this says that it's working. 85 00:05:02,551 --> 00:05:04,508 To stop the app from running, you 86 00:05:04,509 --> 00:05:07,350 should press CTRL+C on the terminal. 87 00:05:08,090 --> 00:05:12,412 And now this message here, well, this message is 88 00:05:12,413 --> 00:05:16,322 saying that, we need to execute some SQL command. 89 00:05:16,323 --> 00:05:19,872 Now this is a good thing with Django because, you 90 00:05:19,873 --> 00:05:24,678 don't really have to execute any SQL query language. 91 00:05:24,679 --> 00:05:30,466 You can just do, python manage.py migrate, 92 00:05:30,467 --> 00:05:36,633 [Author Typing] 93 00:05:36,634 --> 00:05:42,774 press that and Django will execute those queries for you. 94 00:05:42,775 --> 00:05:45,834 So basically these are queries that 95 00:05:45,835 --> 00:05:50,733 create some default tables, database tables. 96 00:05:51,240 --> 00:05:56,666 You can also see that a new db.sqlite3 file was created, 97 00:05:56,667 --> 00:06:02,120 when we executed pythonmanage.py migrate. 98 00:06:03,100 --> 00:06:07,778 So what that command did was it, created an 99 00:06:07,779 --> 00:06:13,128 SQL database file and Django by default uses SQLite 100 00:06:13,129 --> 00:06:18,018 3, but you can also use PostgreSQL, but you can that, 101 00:06:18,019 --> 00:06:21,868 you can easily do that, on the production server. 102 00:06:21,869 --> 00:06:27,366 Luckily, it's good to use SQLite 3, so which is just 103 00:06:27,367 --> 00:06:30,038 one file, and all the data will be there, all 104 00:06:30,039 --> 00:06:32,934 the tables of your project will be there. 105 00:06:32,935 --> 00:06:37,433 So that command generated that file. 106 00:06:38,666 --> 00:06:43,882 And it also applied, all the changes required for the 107 00:06:43,883 --> 00:06:47,780 initial phase of Django project creation. 108 00:06:47,781 --> 00:06:51,998 So it's created some tables and later maybe you 109 00:06:51,999 --> 00:06:54,276 want to make more changes to your tables. 110 00:06:54,277 --> 00:06:56,702 I'll show you how you create new 111 00:06:56,703 --> 00:06:59,980 tables through Django, not through SQL. 112 00:07:00,640 --> 00:07:03,186 So through Python, it's very easy. 113 00:07:03,187 --> 00:07:06,162 And once you create a table in the 114 00:07:06,163 --> 00:07:08,936 Python codes, you have to run that command. 115 00:07:08,937 --> 00:07:11,042 So that will translate your 116 00:07:11,043 --> 00:07:13,500 Python code into SQL queries. 117 00:07:13,501 --> 00:07:17,036 So you don't have to write SQL queries with Django, 118 00:07:17,037 --> 00:07:20,870 you just have to write some easy Python code. 119 00:07:20,871 --> 00:07:23,878 I'll show you how to do that, when we create the app later. 120 00:07:23,879 --> 00:07:25,930 But for now, I can show you 121 00:07:25,931 --> 00:07:28,656 what tables were created inside this file. 122 00:07:28,657 --> 00:07:31,552 If you double click it, it will not be displayed 123 00:07:31,553 --> 00:07:33,690 because, Visual Studio Code 124 00:07:33,691 --> 00:07:36,724 doesn't display SQLite databases. 125 00:07:36,725 --> 00:07:41,348 You need a proper program to see this database. 126 00:07:41,349 --> 00:07:45,620 You don't have to see it, I just want to demonstrate 127 00:07:45,621 --> 00:07:49,752 to you what data this has inside, for learning purposes. 128 00:07:49,753 --> 00:07:53,980 So I have a program here called DB Browser for SQLite. 129 00:07:54,800 --> 00:07:57,458 You can search for that on Google and install it, 130 00:07:57,459 --> 00:08:00,790 or just see here what's, what I'll do. 131 00:08:00,791 --> 00:08:02,566 You don't need this program just 132 00:08:02,567 --> 00:08:04,880 to see the data for Curiosity. 133 00:08:05,460 --> 00:08:07,840 So you want to open the database. 134 00:08:07,840 --> 00:08:09,940 [No Audio] 135 00:08:09,941 --> 00:08:14,320 So that is db.sqlite3 that we have the file. 136 00:08:14,321 --> 00:08:17,510 And so you see that, there are several tables here. 137 00:08:18,040 --> 00:08:19,872 These are tables concerning 138 00:08:19,873 --> 00:08:22,234 the admin interface actually. 139 00:08:22,235 --> 00:08:26,206 So not tables are being created yet, for 140 00:08:26,207 --> 00:08:29,838 things like blogs or other features, that we 141 00:08:29,839 --> 00:08:32,573 are going to have for our Django project. 142 00:08:32,574 --> 00:08:36,596 So things in Django are saved in databases 143 00:08:36,597 --> 00:08:39,528 and Django uses SQLite 3 by default, 144 00:08:39,529 --> 00:08:41,698 as I told you before. Each of 145 00:08:41,699 --> 00:08:43,265 these tables of course have data, 146 00:08:43,266 --> 00:08:48,808 so you can go to Browse Data, and browse these tables. 147 00:08:48,809 --> 00:08:50,572 For now they are just empty 148 00:08:50,573 --> 00:08:53,292 because, you see it's just empty. 149 00:08:53,293 --> 00:08:57,490 We haven't added any users to the admin interface yet. 150 00:08:59,300 --> 00:09:02,134 So what is the admin interface anyway? 151 00:09:02,135 --> 00:09:05,990 Well, let me start the server again. 152 00:09:07,240 --> 00:09:11,296 Go to the website and if you go to the URL, 153 00:09:11,297 --> 00:09:17,790 so after the port, you do slash and then admin, enter. 154 00:09:17,791 --> 00:09:20,670 You will see this Log in box here. 155 00:09:20,671 --> 00:09:22,852 You need the Username of the admin 156 00:09:22,853 --> 00:09:25,108 and the Password of the admin. 157 00:09:25,109 --> 00:09:29,176 Currently we don't have an admin user created 158 00:09:29,177 --> 00:09:32,546 yet, that is also why you see all 159 00:09:32,547 --> 00:09:36,210 these tables are empty, so not data. 160 00:09:36,211 --> 00:09:37,938 So there are tables, but there 161 00:09:37,939 --> 00:09:40,620 are no rows in these tables. 162 00:09:41,540 --> 00:09:43,718 So later on, I'm going to show 163 00:09:43,719 --> 00:09:47,196 you how to create an admin user. 164 00:09:47,197 --> 00:09:51,700 So why do we need the admin interface anyway? 165 00:09:51,701 --> 00:09:54,298 Well, we said that we are going 166 00:09:54,299 --> 00:09:57,536 to build a website that contains blogs. 167 00:09:57,537 --> 00:10:00,992 Now, who is going to add content in these blocks? 168 00:10:00,993 --> 00:10:03,322 Is it you, the developer, or 169 00:10:03,323 --> 00:10:07,050 maybe some authors, who write content? 170 00:10:07,051 --> 00:10:09,502 So these authors, there are two 171 00:10:09,503 --> 00:10:10,734 ways to write that content. 172 00:10:10,735 --> 00:10:14,206 Either they go to your Visual Studio Code project and 173 00:10:14,207 --> 00:10:17,550 then you show them the Python files where the content, 174 00:10:17,551 --> 00:10:21,340 or the HTML files, where the content will be written. 175 00:10:22,320 --> 00:10:27,122 Or a smarter way is to have a 176 00:10:27,123 --> 00:10:31,404 friendlier interface, where you have these content boxes 177 00:10:31,405 --> 00:10:34,166 and you have options to change the fonts. 178 00:10:34,660 --> 00:10:39,286 So buttons, and tools, toolboxes and things like that. 179 00:10:39,287 --> 00:10:43,302 So a real word processing experience like 180 00:10:43,303 --> 00:10:46,580 Microsoft Word or other word processors. 181 00:10:46,581 --> 00:10:48,662 So it's easy for authors to 182 00:10:48,663 --> 00:10:52,000 add content continuously to that website. 183 00:10:52,580 --> 00:10:56,254 So you give those authors admin login, a 184 00:10:56,255 --> 00:10:58,238 Username and a Password, so then they can 185 00:10:58,239 --> 00:11:00,542 go to your website and add content. 186 00:11:00,543 --> 00:11:01,902 We're going to look at the 187 00:11:01,903 --> 00:11:04,730 admin interface in the next video. 188 00:11:05,660 --> 00:11:09,500 So that is what we had, for now. 189 00:11:09,900 --> 00:11:12,033 Thanks for following, I'll talk to you later.