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',
    }
}

posted on 2017-09-13 18:26  run_qin  阅读(202)  评论(0编辑  收藏  举报

导航