[PYTHON] The easiest way to get started with Django

Get started with Django

I've only touched bottles until now, but I'm thinking of working on Django and just building the environment for the time being. I've been using Python 2 for a long time, so I've stumbled upon the introduction of the latest version of Django, so I'll summarize it.

Please install Python3 for the time being.

Building a virtual environment

I thought it would be a hassle to create a virtual environment, but I realized that it would be more troublesome not to create a virtual environment. We recommend that you create a virtual environment with Sokko. It is a waste of about 6 hours to do it without creating a virtual environment.

Create a folder with the name Djangoproject. We will build an environment here.

$ sudo pip install virtualenv
$ sudo pip install virtualenvwrapper

Let's move to the Djangoproject directory and build it.

$ cd Djangoproject
$ virtualenv --python="`which python3.5`" virtualenv

Enable the virtual environment.

$ source virtualenv/bin/activate

Success if it starts with (virtualenv) ~.

Install Django and do the initial setup

Install Django with the virtual environment enabled in the Djangoproject directory.

$ sudo pip install django

Check with pip freeze to see if it works. Maybe Django 1.10 ~ is included.

Create a project.

$ django-admin startproject mysite

The old Django was django-admin.py, so the command has changed.

mysite/   manage.py   mysite/    init.py    settings.py    urls.py    wsgi.py

If it looks like the above, you are successful. Next, let's create an application.

$ cd mysite
$ python manage.py startapp myapp

myapp/   init.py   admin.py   apps.py   migrations/      init.py   models.py   tests.py   views.py

It is OK if it has the above configuration.

After that, we will set it according to the tutorial.

myapp/views.py



from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world.")

Be careful here. Create a urls.py in myapp /.

myapp/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'^myapp/', include('myapp.urls')),
    url(r'^admin/', admin.site.urls),
]

mysite/settings.py


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp', #Add this wording
]

If you can do this, the initial settings are complete. Return to mysite directory

$ python manage.py runserver

http://localhost:8000/myapp/

You should be able to check at.

Now that you've done that, let's display the template in Django. http://qiita.com/Gen6/items/a5562c36fc5c67c89916

Roughly, I summarized it in a book. https://www.amazon.co.jp/dp/B071S25M33

Recommended Posts

The easiest way to get started with Django
How to get started with Django
Step notes to get started with django
The easiest way to get started in Slack socket mode (Go)
The easiest way to synthesize speech with python
The easiest way to use OpenCV with python
Get started with Django! ~ Tutorial ⑤ ~
Get started with Django! ~ Tutorial ④ ~
Get started with Django! ~ Tutorial ⑥ ~
Link to get started with python
How to get started with Scrapy
How to get started with Python
The easiest way to make Flask
The easiest way to try PyQtGraph
Minimum knowledge to get started with the Python logging module
Probably the easiest way to create a pdf with Python3
I tried to get started with Hy
Get started with the documentation tool Sphinx
How to get started with laravel (Linux)
Get started with the Python framework Django on Mac OS X
Here's a brief summary of how to get started with Django
I tried to get started with Bitcoin Systre on the weekend
The fastest way to get camera images regularly with python opencv
The easiest way to get Chainer v1.5 + CUDA + cuDNN on Windows
Django 1.11 started with Python3.6
Getting Started with Django 1
Introduction to Python with Atom (on the way)
Get started with MicroPython
Get started with Mezzanine
A layman wants to get started with Python
Getting Started with Django 2
How to get started with the 2020 Python project (windows wsl and mac standardization)
The easiest way to set up Last-Modified in Flask
I tried to get started with blender python script_Part 01
I tried to get started with blender python script_Part 02
Try to get the contents of Word with Golang
Transit to the update screen with the Django a tag
What I did to get started with Linux commands
Get started with influxDB + Grafana
Getting Started with Python Django (1)
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Get started with Python! ~ ② Grammar ~
Getting Started with Django with PyCharm
Getting Started with Python Django (5)
I want to get started with the Linux kernel, what is the list head structure?
How to get started with Visual Studio Online ~ The end of the environment construction era ~
The only way to get iter_rows back to the beginning with openpyxl is to reload the file with load_workbook.
Memo to get the value on the html-javascript side with jupyter
Get the package version to register with PyPI from Git
I tried to get started with Hy ・ Define a class
Explaining how to make LINE BOT in the world's easiest way (2) [Preparing a bot application in a local environment with Django in Python]
I can't log in to the admin page with Django3
The usual way to add a Kernel with Jupyter Notebook
How to get into the python development environment with Vagrant
[Introduction to Python] How to get data with the listdir function
Get the source of the page to load infinitely with python.
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
Steps to develop Django with VSCode
Get started with Python! ~ ① Environment construction ~