I will write it assuming our employees who want to try it but cannot do it because the threshold is high.
The Django project name is tentatively "test-oauth-client". [^ 1]
[^ 1]: Was test-oauth-consumer
a more appropriate name ...
PyCharm is a paid Python development environment.
http://brew.sh/index_ja.html From here.
[^ 2]: Until now, when I read "Home Brew", it was pointed out that "It's Home Blue". When I watch the YouTube video, it looks like "Home Blue".
$ brew install python3
When complete, the pyvenv-3.5
command will be installed with it.
We will use pyvenv-3.5, which was installed with Python3 earlier.
$ cd
$ mkdir .virtualenvs
$ pyvenv-3.5 .virtualenvs/test-oauth-client
A Python3.5 virtual environment is created in the home directory /.virtualenvs/test-oauth-client
.
The name of your virtual environment doesn't have to match the Django project name, but it's easier to see.
$ . .virtualenvs/test-oauth-client/bin/activate
↑ It is a dot command. The same is true for source .virtualenvs / test-oauth-client / bin / activate
.
(Test-oauth-client)
is added to the prompt.
This means that you have entered a virtual environment.
$ python --version
Python 3.5.1
$ /usr/bin/env python --version
Python 3.5.1
$ which python
/Users/ytyng/.virtualenvs/test-oauth-client/bin/python
The default Python location changes only while you are in the virtual environment.
To get out of the virtual environment
$ deacitvate
It may be useful to have a Python library called "** virtualenvwrapper **" to enter the virtual environment (not mentioned here).
Activate it to install Django on your virtual environment.
$ cd
$ . .virtualenvs/test-oauth-client/bin/activate
Create a test-oauth-client directory under a directory of your choice. This is the root of the repository.
$ cd workspace
$ mkdir test-oauth-client
$ cd test-oauth-client
You have Django installed to create the project directory with Django commands.
$ pip install django
2-3. startproject
Create a Django project in the directory you just saw. It's a good idea to move your Django project down one level from the repository root.
$ pwd
/Users/ytyng/workspace/test-oauth-client
$ django-admin.py startproject test_oauth_client
The test_oauth_client directory is created.
$ cd test_oauth_client
$ ./manage.py
Confirm that the subcommand list is displayed without any error.
$ ./manage.py migrate
The initial database is created. SQLite3 is used by default.
It's a project that doesn't do anything at all, but let's start a test HTTP server for now.
$ ./manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
May 23, 2016 - 08:38:32
Django version 1.9.6, using settings 'test_oauth_client.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
If it is output like this, it is running.
In your browser, try accessing http://127.0.0.1:8000/
.
If you see "It worked!", Django is running.
After confirming the operation, press Ctrl + c
on the terminal to shut down the server.
https://www.jetbrains.com/pycharm/ Please install from here. You can try it for 30 days.
Go to the repository root
$ cd ~/workspace/test-oauth-client/
Start PyCharm
$ charm .
This is the same. $ open -a PyCharm .
You can also double-click the PyCharm icon to start it and open the directory from File → Open.
First, open your preferences.
⌘+,
Enter "** structure **" in the search window and click "Project Structure" in the left pane.
You'll see Django's project root, ** test_oauth_client ** (one level below the repository root), click it to select it, and click ** Sources **.
A directory will be added to "Source Folders" in the right pane, so click "OK".
Open your preferences. ⌘ +,
Enter "** interpreter **" in the search window.
"Project Interpreter" will appear in the search results, so click it.
Click the "Project Interpreter" pull-down in the right pane to open it, and click "Show All" at the bottom.
The Project Interpreters dialog will be displayed. Click the "+" at the bottom left and select "Add Local".
A file selection dialog will be displayed. Click the home icon on the upper left once.
Then, find the **. Virtualenvs / test-oauth-client ** you registered earlier and open it. In addition, select the ** bin / python ** symbolic link in it and click "OK".
In addition, click "OK" → Return to the Preference window, so after confirming that the virtual environment was selected, click "OK".
In the background, a rescan of the project structure begins.
Open your preferences. ⌘ +,
Enter "** django **" in the search window.
"Django" in Languages & Frameworks will be searched, so click to select it.
Check "Enable Django Support".
Specify test_oauth_client (one level below the repository root) for Django project root
Specify settings.py in settings. Click "OK"
Click the [▼] pull-down in the upper right corner of PyCharm, and click "Edit Configurations ...".
The Run / Debug Configurations dialog opens, click + in the upper right corner and select "Django server"
Name: can be arbitrary, but for the time being, set it to runserver and click OK.
Click the bug button to the right of the two pull-downs. It will be in debug execution mode.
If you try to access http://127.0.0.1:8000/ with a browser, the demo page will be displayed.
You are ready to debug in PyCharm.
Now, since the current project content is the default, there isn't even a program to set breakpoints, so let's add breakpoints in Django's code.
On PyCharm, press Shift four times and enter "** get_response **" in the search window. There are some get_responses that apply, but choose the one that says ** BaseHandler in ... **.
The get_response method of the BaseHandler class is displayed, and you can set a breakpoint by clicking on the left side of the editor pane.
Then reload the browser and you should be able to stop at the breakpoint and step through or see the variables in the debugger.
Recommended Posts