Python? django? Environment construction? Correct understanding?
** I want to use django for the time being! !! !! !! (ˇΩˇ) **
Even though I am motivated, I can't stumble when building an environment! So, I will send you the environment construction without understanding even 1 mm from me on the first day of Python history and django history.
https://docs.djangoproject.com/en/1.11/intro/tutorial01/ At the moment, 1.11 is the latest in django, but if it's updated in the future, change the URL above to something like 1.12 and that's the latest documentation. that's all.
If you read the document, you'll understand it, it's too much to throw at you, so let's explain it. But I won't go into the details. I can not do it! !! Python formula or ANACONDA You can create an environment to run Python locally, but
--Heavy ――Unexpectedly, it takes time ――I don't really understand
People who are new to Python will surely be like this.
--No installation required --Just register ――Various environments are in place --Easy to deploy!
** So let's use Cloud9 ! !! ** **
When you log in to Cloud9, you will access the following page. Let's create a workspace with [Create a new workspace].
Then you will be taken to the following page, so select the Workspace Name ** "mysite" ** from the template below, ** "django" ** from the template below, and press [Create workspace]. ..
Once the workspace is created, the screen will change to the one shown below.
Well, the first thing to do is to check the version. The official documentation assumes ** Python 3.4 or higher and django 1.11 **. Let's check the version by entering the following in bash.
bash
python --version
python -m django --version
Execution result Yes old, yes sieve. So I will raise the version.
Let's do the following in bash without thinking.
bash
sudo mv /usr/bin/python /usr/bin/python2
sudo ln -s /usr/bin/python3 /usr/bin/python
python --version
Execution result
bash
sudo pip3 install django
python -m django --version
Execution result The prerequisites are now in place! Next, let's create an application.
Run the following to create an application called "polls".
bash
python manage.py startapp polls
Execution result As mentioned above, a folder called "polls" and various files are created directly under it. This completes the application creation!
This also follows the official documentation and modifies views.py as follows:
polls/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
This is all you need for the view part!
Just follow the official documentation! Even so, why don't you read it through to Tekito? So let's read the document properly!
Right-click on the polls folder to display various context menus, so select [New File] in it. Since a new file will be created, name it [urls.py] and copy and paste the following
polls/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
If you can do it so far, let's actually move it. Click [Run Project] in the upper right.
The following log should be spit out
The URL is output when the project is executed. In this case, it is the following URL. Please try to access it. https://mysite-karimata.c9users.io
When I fly ... that? can not fly?
That should be it. This time I made a page called "polls". Try adding "polls" to the end of the URL (https://mysite-karimata.c9users.io/polls/). Then ...! Yes, I was able to display it! For the time being, the minimum environment has been created! We did it, Tae-chan! You can do Python!
If you follow the above flow, you can build an environment using django without really understanding even 1 mm. As I will learn the details one by one, ** I can move it first! Let's enter from ** and lower the psychological barrier!
Have a good Python life!
Recommended Posts