Django入门之自定义页面

it2022-05-06  1

1.创建项目,创建app

django-admin.py startproject HelloWord python3 manage.py startapp sync_one #第二步需要进入HelloWord目录执行

详情猛击

2.修改views.py文件

from django.shortcuts import render from django.shortcuts import HttpResponse # Create your views here. def home(request): return HttpResponse("Hello word")

#黄色部分为新增

3.修改url.py文件

"""django1 URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.9/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from app01 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^home/', views.home), ] #一个url一个函数

4.启动项目

kamil@kamil-ThinkPad-X260:~/PycharmProjects/django1$ python3 manage.py runserver 127.0.0.1:8000 Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them.

5.测试

6.后台配置

kamil@kamil-ThinkPad-X260:~/PycharmProjects/django1$ python3 manage.py makemigrations #生成配置文件 kamil@kamil-ThinkPad-X260:~/PycharmProjects/django1$ python3 manage.py migrate#根据配置文件创建数据库相关 Operations to perform: Apply all migrations: auth, sessions, admin, contenttypes Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying sessions.0001_initial... OK No changes detected kamil@kamil-ThinkPad-X260:~/PycharmProjects/django1$ python3 manage.py createsuperuser#创建用户

 

转载于:https://www.cnblogs.com/kamil/p/5547666.html

相关资源:DirectX修复工具V4.0增强版

最新回复(0)