Django only takes 10 steps to build a website. Let’s count… Pycharm (Pycharm) – Pycharm (Pycharm) – Pycharm (Pycharm) For example: a coworker wants to send you a gigabyte file and you send him a link to a website. After he uploads, the file is on your computer! Here is a GIF of the demo: Upload from F disk of computer through browser, files appear in D disk, here browser upload files can be on any other computer, upload files will be saved in your D disk!

Install Pycharm Pro

Note that Pycharm requires a professional installation

Django website setup

The first step

When Pycharm is on, create a New Project: Click on File in the upper left corner — New Project to create the Project pop-up box, which is the icon in step 2.

The second step

To create the project content, click Django to the left and type the project address + project name in the upper Locattion text box. The Project address in the figure is: “E:\PyCharm Project” The Project name is “Decrypt_Test “, separated by”! Click on “ProjectInterpreter: Python3.7”, will be an option below. Select “Existing Interpreter “(meaning an Existing interpreter) and type the address of your Python environment +python.exe into interpreter. You can manually enter or click the “three dots” control on the right to select the file path. Finally, click Create to Create the project. Can also be in a “ProjectInterpreter: Python3.7” select New environment using, this is the default choice, separate for each project to create a virtual environment. Novice recommended to choose this option, save operation steps! Pycharm install Pycharm install Pycharm install Pycharm install Pycharm install Pycharm ** The second part of this article is the Python environment installation tutorial.

The third step

Step 2 After the project is created, the following dialog box is displayed. Select Open in Current Window and click OK

The fourth step

Clicking OK will take you to the project you just created, as shown below. The settings.py and urls.py files are opened by default, corresponding to the file on the left.

Click on the icon in the lower left corner of the interface, select Terminal, and type Python manage.py startApp Decrypt after the cursor, press Enter, you will see a new folder on the left side of the project, as shown in Figure 2 below:

Step 5

In the Settings. Find the INSTALLED_APPS of py, within the brackets new ‘decrypt. Apps. DecryptConfig’, said registered App. The diagram below:

In settings.py, go to “ALLOWED_HOSTS” and put “*” in parentheses. This code can access your website from any IP address.

Step 6

Look for urlpatterns in urls.py, add path(‘decrypt/,decrypt’) in parentheses,

Step 7

Double-click on the left views.py file to open it and write:

from django.shortcuts import render,redirect # Create your views here. def decrypt(request): If request. Method == "GET": return render(request, "decrypt.html") else: Save_path = "D:/%s" % pic.name with open(save_path, "wb") as f: Get the content of the uploaded file and write to the open file for content in pic.chunks(): F text (content) # return redirect("/decrypt") # return JsonResponse({" MSG ": "OK!") })Copy the code

Step 8

Create a new decrypt.html file in the templates folder on the left, double-click the decrypt.html file on the left to open it, and write the following:

<! DOCTYPE HTML > < HTML lang="en"> <head> <meta charset="UTF-8"> <title> </head> <body> <h4> File upload </h4> <form Action ="/decrypt/" encType ="multipart/form-data" method="post"> {% csrF_token %} Uploads files: <br> <input type="file" name=" PIC "> <br> < form> </body> </ HTML >Copy the code

Step 9

Run python manage.py runserver 172.16.6.224:8000 8000 is the IP address of my computer, you need to change the IP address of your computer, and enter to run, as shown in Figure 2 below, it means successfully run the website! Enter “http://172.16.6.224:8000/decrypt/”, in the browser, pay attention to the IP address to your own IP address. Hurry up and send the website address to your friends, let them give you the data! If the article is helpful to you, remember to like + follow + favorites!

Grow up together

Follow the public account “Python Sword”, here to share Python related knowledge, come and grow with me!