Python Django environment setup tutorial (MAC + pycharm + Django ++ postgreSQL), djangopycharm

Source: Internet
Author: User
Tags django server

Python Django environment setup tutorial (MAC + pycharm + Django ++ postgreSQL), djangopycharm

Setting up the Django environment seems to be a very simple task. In fact, it is not the case that I have struggled for more than half a day, so I would like to summarize the entire setup process here, at the same time, we also hope that our new entry peers will face fewer detours ~

Now, the required tools are as follows:

MAC

Python 2017 for MAC

Jdk1.8

Python3.6

PostgreSQL 9.6.6

Toad/navicat/pgAdmin database tool (optional)

The general requirements for these items are as follows: as to why jdk should be installed, Pycharm itself depends on the java environment. For details, refer to the product description:

Hmm ~, How to install and configure postgreSQL is not described in this chapter, because I have installed the postgreSQL database on a separate linux (debian) host. If necessary, I will talk about it later ~

OK! Now let's take a closer look at the entire configuration process:

A>After all the necessary software is installed, a Pycharm welcome page will be displayed for the first time: the user has created a project on the left side (new users do not have a project here, you can ignore it), and the right side is the project creation type, directly select the first "Create New Project", and then on the left side of the Django Project in the New window, pay attention to the "file directory location" and "Python environment interpreter" on the right ", this environment must be compatible with the current Django version. Here we will talk about it: I use django1.11 and Python3.6. After the selection, there may be a slow download process, wait patiently ~; Figure =

B>Good ~, After entering the main Pycharm interface, the project structure is roughly as follows. It should be noted that the sqlite3 database will be applied by default during running (SEE), um ~, How to run this django project at the beginning? The answer is: Command Line (use the default mac terminal, as shown in the second figure, if Python3 is installed, you are advised to use the python3 command to enable the Service (the default value is "python manage. py runserver ", default port: 8000). For the browser access address, see (http: // 127.0.0.1: 8000), =

Hmm ~, The face-to-face theme project seems to have been completed, but as a practical project development, the following three problems need to be solved:

1> switch to the postgreSQL database

2> it is inconvenient to start the Django project. You need to enable the django service with one click.

3> how to create an App in the current Django project?

C>Now I will summarize the solution to the first problem: configure the PostgreSQL database. If the database is installed on another machine, you need to use the local terminal to remotely access the database (to ensure that the database is truly accessible, how to remotely connect to the database is not the focus of this Article), you need to configure setting under the django project. in The py configuration file, you also need to configure the connection package of the django pg database (equivalent to the jdbc package in the java project) psycopg2 package. After the configuration of the django database is complete, refer to -->

D>After the database is configured, I will summarize how to configure the Django server Service to be enabled with one click.

To enable the service with one click, you only need to configure the service in the menu. Before that, we recommend that you display the shortcut menu (View menu> Toolbar option)

E> the above configuration is complete, but it is not complete. Currently, only a main project is created. This project only contains some basic configurations, generally, a separate App will be created as needed during development. Does it sound very different (if you are a student of java, you will have a question)? The explanation here is: this is the norm for Django projects. It facilitates isolated development of modules in the same project, which is both convenient for development and maintenance. I think so anyway ~; All right, this function is also very simple. You only need to use "run manage" under the Tool menu. py task... "command, then give an App name in the Command window and press enter (if any error is reported, check the cause of the error according to the output log). Note, at the end of this configuration, you need to add the App name to the setting of the main item. in py (INSTALLED_APPS variable!

!! So far, the Django project has been basically built, but there are several minor issues that need to be resolved:

The first command, whether it is to switch the database or create an App, must be executed on the terminal: "python manage. py migrate", to update the project configuration, -->

Second, the project runs normally. How do I know if the project has been successfully switched to the target database? For this question, I want to say: please use the table in the customer's query to know (I use Toad). For details, see the figure -->

As the final conclusion, the first Django page is displayed, which is very low ~, For details about the Add process, refer to. If you have not explained any problems, search for them by yourself ~

The last one (a little too long ~), We are very grateful to the domestic and foreign communities for the successful construction of this project. These communities include but are not limited to: stackoverflow, open source China, and self-improvement school django tutorials. Let's also say: stackoverflow is a very good developer Q & A platform, for me to solve a lot of development problems, it is recommended that readers go inside --> https://stackoverflow.com/

The above Python Django environment setup tutorial (MAC + pycharm + Django ++ postgreSQL) is all the content that I have shared with you. I hope to give you a reference, we also hope that you can support the customer's home.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.