• django models,views,urls,settings


    models:

    from django.db import models
    class UserInfo(models.Model):
        userName = models.CharField(max_length=12)
        passWord = models.CharField(max_length=12)
        age = models.IntegerField()
        def __str__(self):
            it = (',',self.passWord,',',str(self.age))
            return self.userName.join(it)

    views:

    from django.shortcuts import render
    from reginster.models import UserInfo
    def reginster(request):
        u = UserInfo(userName ='root',passWord = 'root', age =12)
        u.save()
        return render(request,'reginster.html',context={
                'userInfo':UserInfo.objects.all()
            })

    project_name/urls:

    from django.conf.urls import url,include
    from django.contrib import admin

    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^reginster/',include('reginster.urls'))
    ]

    app_name/urls:


    from django.conf.urls import url
    from . import views

    urlpatterns = [
        url(r'',views.reginster,name = 'reginster')
    ]

    settings:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR,'templates')], #templats/app_name
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME':'mydatabase',
            'USER':'root',
            'PASSWORD':'root',
            'HOST':'127.0.0.1',
            'POST':'3306',
        }
    }

  • 相关阅读:
    关于WEB页面的强制分页打印问题
    iOS地图多个自定义大头针绘制核心代码
    PHP生成随机码
    安卓动画小结
    WKWebView遇到的问题汇总
    实现图片预加载的几种方式
    苹果所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程
    markdown语法博客园测试
    Agreement has been updated--Edit Phone Number最便捷解决办法(不需要安全提示问题和双重认证)
    Python黑帽子:自动化内存取证
  • 原文地址:https://www.cnblogs.com/sayHello2World/p/7516640.html
Copyright © 2020-2023  润新知