Python's Django environment construction (MAC+pycharm+Django++postgreSQL)



Python's Django environment construction (MAC+pycharm+Django++postgreSQL)

 

Please indicate the address for reprint: http://www.cnblogs.com/funnyzpc/p/7828614.html Building

  

  a Django environment seems to be a very simple thing, In fact, it is not. I have tossed for a long time, so I will summarize the whole construction process here. At the same time, I also hope that my colleagues who are just getting started will avoid detours~

Now, the tools needed:

    MAC computer

    Pycharm 2017 for MAC

    jdk1.8

    Python3. 6

    postgreSQL 9.6.6

    Toad/navicat/pgAdmin database tools (not necessary)

generally need these things. As for why jdk is installed, it is probably that Pycharm itself partly depends on the java environment. You can take a look at the product description for a glimpse:

 

 

  um~ , and how to install and configure postgreSQL is not listed in this chapter, because I installed the pg database on a separate linux (debian) host, if necessary, I can talk about it later~

OK! Now start to elaborate on the entire configuration process:

A> After installing all the necessary software, there will be a Pycharm welcome page when you open it for the first time: the left side is the project that the user has created (the new user does not have it here, you can ignore it), the right side is the project creation type, directly select the first A "Create New Project" is enough, then in the new window on the left side of the Django project, and pay attention to the "file directory location" and "Python environment interpreter" on the right side, this environment must be compatible with the currently created Django version, Let me talk about it here: I am using django1.11 and Python3.6. After selecting, there will probably be a download process that may be slow, please wait patiently~; Figure =="

 

  

B>Okay~, after entering the main interface of Pycharm, the project will be displayed. It is probably the structure shown below. What needs to be explained here is that the sqlite3 database will be applied by default (see the figure below), um~, how to run this django project at the beginning, the answer is: command line (need to use The default terminal of mac, as shown in the second picture below), the main thing to note here is that if users with Python3 are recommended to use commands starting with python3 to use python3 to start the service (the default is "python manage.py runserver", the default The port number is 8000), and the browser access address is also shown in the figure below (http://127.0.0.1:8000). The figure below == "

 

 

Well~, the face-to-face theme project seems to have been completed, but as an actual project development, it is required here. Solve the following three problems:

  1> need to switch to the postgreSQL database 

  2> start the Django project and its inconvenience, you need to open the django service with one 

  click : 16px; color: #ff0000"> 3> How to create a new App in the current Django project?

C> Now I start to summarize the solution to the first problem: configure the pg database, if the database is installed on other machines, you need to use the local terminal to remotely access the database (to ensure that the database is in a state that can really be connected, how to remotely Connecting to the database is not the focus of this article and will be skipped temporarily), you need to configure the setting.py configuration file under the django project, and you also need to configure the connection package of django's pg database (equivalent to the jdbc package in the java project) psycopg2 package, so the django database After the configuration is completed, refer to the following figure for details-->

 

 

 

 

D> The database configuration is completed. Next, I will summarize how to configure the Django server service to start with one click. To

  configure the one-click service, you only need to configure it in the menu. Before that, it is recommended to set the The shortcut menu is displayed (View menu -> Toolbar option)

 

 

 

 

E> The above configuration is completed, but it is not actually completed. The current creation is only a main project. This project only contains some basic configuration, general development When you need to create a separate App, it sounds very different (if you are a student of java, you will have doubts), the explanation I give here is: This is the specification of the Django project, which is convenient for the same one The modules of the project are developed in isolation, which is convenient for both development and maintenance. Anyway, I think so~; well, this function is also very simple, just use the "run manage.py task..." command under the Tool menu, Then give the name of an App in the command window and press Enter (if there is an error, please check the reason for the error according to the output log). Note that at the end of this configuration, the name of the App needs to be added to the setting.py of the main project ( INSTALLED_APPS variable) can only be used

 

 

!!! So far, the Django project has been basically built, but there are a few small problems that need to be hung up:

  The first point "Whether you are switching databases or creating a new App, you must execute this command in the terminal: "python manage.py migrate", this command is to update the project configuration, as shown in the figure-->

 

  Second point "Project Normal operation, how to know whether the project has been successfully switched to the target database? What I want to say about this question is: Please use the table in the customer's query to know it (I use Toad), see the picture-->

 

As the final concluding remark, show the first Django page, Very low~, please refer to the figure below for the specific addition process. I don’t explain much about the problem and search it by myself.

 

 

      The last (a bit long-winded~), the smooth construction of this project is very grateful to the domestic and foreign communities, including but not limited to : Stackoverflow, Open Source China, and the Django tutorial of Ziqiang Xuetang, and at the same time: stackoverflow is a very good Q&A platform for developers, which has solved a lot of development problems for me. I suggest readers to go in and walk around --> https:// stackoverflow.com/

 

is now: 2017-11-21 20:16:42 (Tuesday), good night everyone\( ̄︶ ̄)/

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397798&siteId=291194637