Hello. This is Sugimoto. p>
I wrote this article for you, "I want to make a website with Python." "I read the net and reference books about Django, but I don't understand." p>
I am writing for beginners and beginners, so I will not explain it in depth. please note that. p>
Also, the following assumptions are made. p>
This time, I will create a simple blog application with Django.
Then, Let's Django! p>
Step No. th> | Contents th> |
---|---|
1 | Virtual environment construction / setting td> |
2 | Create project (folder) td> |
3 | Corresponds to Japan time and Japanese td> |
4 | Display Django page td> |
5 | What's next? td> |
In this item, you will create a virtual environment and install Django in that virtual environment. strong> (Roughly speaking, a virtual environment is a "pseudo OS". We will create a web application on this pseudo OS.) P>
First, create a directory on your desktop for this tutorial. The directory name can be anything, but this time it's "django_work". p>
I will enter this immediately. Did you see a black screen? When it comes up, enter the following command into the django_work directory. p>
Let's create a virtual environment here! Enter the following command in the terminal. p>
Then you should have a directory called django_venv in your django_work directory. This is a virtual environment. p>
This completes the construction of the virtual environment. It was easy! p>
This is just "creating a virtual environment". You have to start the virtual environment. p>
Continue to type the following command while still in the django_work directory. Start the virtual environment. p>
The virtual environment is now started. It was easy again! p>
Finally, install Django. Enter and execute the following commands line by line. p>
You've now installed Django in your virtual environment. By the way, the version of Django is 2.2.6. p>
This completes the construction and settings of the virtual environment. p>
project is a folder that contains configuration files and applications to be created in the future. strong> Enter the following command while the virtual environment is still running. The project name is "sakusaku_blog". p>
The project is now created. If you look in the django_work directory on your desktop, you'll see that a directory called "sakusaku_blog" has been created. p>
Finally, in , type the following command in the terminal to enter the project. p>
The project (directory) has been created. Please let the terminal wait for a while in this state. It will be used in the item "Displaying the Django page" that follows. p>
When you run the django-admin startproject command earlier, the Django configuration file is automatically generated. The name of the configuration file is "settings.py".
Rewrite the relevant part in this settings.py to correspond to Japanese and Japan time. p>
Open the sakusaku_blog directory in the django_work directory with a text editor (VSCode, Atom, etc.). Then you will find the "settings.py" file in the sakusaku_blog directory. Look at the contents of this file. p>
I think there is a code "LANGUAGE_CODE ='en-us'" around line 106. Now you can change to Japanese and Japan time! p>
That's all for making Japan time and Japanese compatible. p>
Start the server and finally display the Django page! p>
Please open the terminal. You should be in sakusaku_blog now. p>
Type the following command in the terminal to start the server. p>
The server has started! Try accessing http: // localhost: 8000 ! Congratulations! Now it's sunny and Django's environment construction is complete! strong> p>
From the next time, we will create an application! looking forward to! p>
Thank you for reading this far. p>
I hope you find it surprisingly easy to launch Django. p>
I'm currently writing "How to create an application" and "Django crispy tutorial (Environment construction on Windows)", so please wait for a while. p>
(I'd be happy if you could press the "Like" button at the end) p>
Let's study Django together ٩ ('ω') و p>
Recommended Posts
Open a terminal in Finder → Applications → Utilities → Terminal. p>
Terminal
$ cd Desktop/django_work
Terminal
$ python3 -m venv django_venv
Terminal
$ source django_venv/bin/activate
Terminal
(django_venv) $ pip install --upgrade pip
Terminal
(django_venv) $ pip install django==2.2.6
Create project (directory) h2>
The configuration file is automatically generated by typing the following command. p>
Terminal
(django_venv) $ django-admin startproject sakusaku_blog
Terminal
(django_venv) $ cd sakusaku_blog
Corresponds to Japan time and Japanese h2>
You can set the language to Japanese by rewriting this "'en-us'" part to "'ja-JP'".
Also, if you rewrite the value of the code "TIME_ZONE ='UTC'" to "'Asia / Tokyo'" around the 108th line, you can set it to Japan time. p>
Display Django page h2>
Terminal
(django_venv) $ python3 manage.py runserver
You should see the Django default page. p>
What's next? h2>