Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Introduction: usually we visit the premise of the website is – know the URL of the website to visit, you can go to see the website we want to see; All the server has to do is set up the URL so that the user can access the corresponding resource!

Basic URL concepts and formats

(1) Basic concept and format of URL

1. The concept of url:

Uniform Resoure Locator (URL) a Uniform Resource Locator (URL) is a concise representation of the location and access method of available resources on the Internet. It is the address of a standard resource on the Internet. Every file on the Internet has a unique URL that contains information indicating where the file is and what the browser should do with it.

2. The url:

http://127.0.0.1:8000/hello/

Schema ://host[:port#]/path/… /[? Query-string][#anchor] schema: specifies the protocol to use (for example, HTTP, HTTPS, FTP) host: SPECIFIES the IP address or domain name of the HTTP server. Port: specifies the port number, the default HTTP port is 80. Path to access resource query-string: data sent to HTTP server: anchor: anchor #

3. What the urls.py file does (important!)

The URL configuration (URLconf) is like a directory for the web sites Django supports. Its essence is a mapping table between the URL schema and the view functions to be called for that URL schema. This tells Django to call the corresponding section of code for that URL. The url is loaded from the configuration file.

(2) Use URL in Django project:

The urls.py file is created automatically after a Django project is created:

"""dj_test URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.1/topics/http/urls/ Examples: the Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """
from django.contrib import admin
from django.urls import path           
from . import views

urlpatterns = [     # main by
    path('admin/', admin.site.urls),
    The essence of URL configuration is a mapping table between the URL schema and the view functions to be called for that URL schema
    path('test/', views.test),    
	The first parameter is the path parameter in the URL. The second parameter is the view function associated with this URL.
]
Copy the code

② Views. py is a view function file that needs to be created in the project:

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
View operation

def test(request) :   # function view
    return HttpResponse("This is the handsome guy.")
Copy the code

Note that:

🔆 In The End!

Start now, stick to it, a little progress a day, in the near future, you will thank you for your efforts!

This blogger will continue to update the basic column of crawler and crawler combat column, carefully read this article friends, you can like the collection and comment on your feelings after reading. And can follow this blogger, read more crawler in the days ahead!

If there are mistakes or inappropriate words can be pointed out in the comment area, thank you! If reprint this article please contact me for my consent, and mark the source and the name of the blogger, thank you!