An example of combining Django with pyecharts

2871 단어 Django
1. Create Application
Go to the sibling directory of manage.py and run:

py manage.py startapp NLP

sitting.py Application:


# Application definition
# Django 
INSTALLED_APPS = [
    'polls.apps.PollsConfig',# polls 
    'NLP'
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

NLP , views.py, , index


from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the NLP index.")

、 URLconf

1、 index URL , urls.py , :


from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

 path()

route( )

route is a criterion for matching URLs (regular expression-like). When Django responds to a request, it starts with the first item in urlpatterns and matches the items in the list in order until it finds a match.
view (required)
When Django finds a matching criterion, it calls that particular view function, passing in an HttpRequest object as the first argument, and the "captured"arguments are passed in as keyword arguments.
name (optional)
Naming a URL allows you to uniquely refer to it anywhere in Django, especially in templates. This useful feature allows you to change a URL pattern globally by changing only one file.
kwargs (optional)
Any number of keyword arguments can be passed to the target view function as a dictionary.
2. Create the newly created NLP urls module in the root URLconf, open mysit/urls.py, and insert an include() in its urlpatterns module:


from django.contrib import admin
from django.urls import path,include

urlpatterns = [
	path('admin/', admin.site.urls),
        path('NLP',include('NLP.urls')),# app NLP url
]

inclde() URLconfs。 Django :func:~django.urls.include  , URL , URLconf 。

, :


py manage.py runserver

 

 

좋은 웹페이지 즐겨찾기