在创建项目,完成基础设置后
首先写Models配置模型创建表
from django.db import models
# Create your models here.
class UserInfo(models.Model):
username = models.CharField(max_length=30)
password = models.CharField(max_length=50)
gender = models.BooleanField(default=1)
telphone = models.IntegerField(max_length=20)
email = models.CharField(max_length=50)
#注意是ImageField()
image = models.ImageField()
is_active = models.BooleanField(default=False)
然后写Views创建我们的测试方法
from django.shortcuts import HttpResponse
def register(request):
if request.method == 'GET':
return HttpResponse('get')
配置urls
-
项目同名文件urls下
from django.conf.urls import patterns, include, url from django.contrib import admin urlpatterns = patterns('', # Examples: url(r'^admin/', include(admin.site.urls)), url(r'^register/',include('register.urls')) )
-
app urls下
from django.conf.urls import patterns, url from .views import register urlpatterns = patterns('', url(r'^index', register), )