zoukankan      html  css  js  c++  java
  • Django入门之自定义页面

    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
    #创建用户
    公众号请关注:侠之大者
  • 相关阅读:
    融云会话界面导航上移-使用IQKeyboardManager
    App调用safar
    info.plist 安全登录
    could not find developer disk image
    easyExcel使用以及踩过的坑
    springBoot配置文件详解
    jvm面试题(纯手撸)
    面试题
    设计模式之观察者模式(Observer)
    设计模式之模板方法(TemplateMethod)
  • 原文地址:https://www.cnblogs.com/kamil/p/5547666.html
Copyright © 2011-2022 走看看