django models,views,urls,settings

Posted run_qin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘)],
        ‘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‘,
    }
}

以上是关于django models,views,urls,settings的主要内容,如果未能解决你的问题,请参考以下文章

Django框架

web框架---Django之MTV模型

Django框架篇

django中函数之间的关系

django 学习一

django安装与简介