完成了以下工作:
1、学习了Django框架基础,了解了每一个文件的作用及其配置方法
2、连接上了服务器上的数据库,并建立了VJ数据库
建库命令如下
CREATE TABLE `vj`.`user` (
`userid` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`account` VARCHAR(15) NOT NULL,
`key` VARCHAR(20) NOT NULL,
`nickname` VARCHAR(20) NULL,
`sex` VARCHAR(2) NOT NULL,
`university` VARCHAR(20) NULL,
`blog` VARCHAR(100) NULL,
`isAdmin` TINYINT NOT NULL,
`desc` LONGTEXT NULL,
`submitted` INT NOT NULL,
`accepted` INT NOT NULL,
PRIMARY KEY (`userid`),
UNIQUE INDEX `account_UNIQUE` (`account` ASC),
UNIQUE INDEX `userid_UNIQUE` (`userid` ASC));
CREATE TABLE `vj`.`problem` (
`proid` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`originoj` VARCHAR(10) NOT NULL,
`problemid` VARCHAR(10) NOT NULL,
`problemurl` VARCHAR(100) NOT NULL,
`title` VARCHAR(100) NOT NULL,
`desc` LONGTEXT NOT NULL,
`timelimit` INT NOT NULL,
`memeorylimit` INT NOT NULL,
`input` LONGTEXT NOT NULL,
`output` LONGTEXT NOT NULL,
`sampleinput` LONGTEXT NOT NULL,
`sampleoutout` LONGTEXT NOT NULL,
`updatetime` DATETIME NOT NULL,
PRIMARY KEY (`proid`));
CREATE TABLE `vj`.`contest` (
`contestid` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`contestname` VARCHAR(45) NOT NULL,
`contestpro` VARCHAR(255) NOT NULL,
`contest_s_time` DATETIME NOT NULL,
`contest_l_time` INT NOT NULL,
`contest_admin` INT NOT NULL,
PRIMARY KEY (`contestid`));
CREATE TABLE `vj`.`test` (
`testid` INT NOT NULL,
`proid` INT NOT NULL,
`code` LONGTEXT NOT NULL,
`timec` INT NULL,
`memoryc` INT NULL,
`result` VARCHAR(20) NOT NULL,
`time` DATETIME NOT NULL,
`userid` INT NOT NULL,
PRIMARY KEY (`testid`));
3、建立了VJ的Django框架,设置了setting.py和model.py,连接数据库以及建立模型。
model.py:
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from __future__ import unicode_literals
from django.db import models
class Contest(models.Model):
contestid = models.AutoField(primary_key=True)
contestname = models.CharField(max_length=45)
contestpro = models.CharField(max_length=255)
contest_s_time = models.DateTimeField()
contest_l_time = models.IntegerField()
contest_admin = models.IntegerField()
class Meta:
managed = False
db_table = 'contest'
class DjangoMigrations(models.Model):
app = models.CharField(max_length=255)
name = models.CharField(max_length=255)
applied = models.DateTimeField()
class Meta:
managed = False
db_table = 'django_migrations'
class Problem(models.Model):
proid = models.AutoField(primary_key=True)
originoj = models.CharField(max_length=10)
problemid = models.CharField(max_length=10)
problemurl = models.CharField(max_length=100)
title = models.CharField(max_length=100)
desc = models.TextField()
timelimit = models.IntegerField()
memeorylimit = models.IntegerField()
input = models.TextField()
output = models.TextField()
sampleinput = models.TextField()
sampleoutout = models.TextField()
updatetime = models.DateTimeField()
class Meta:
managed = False
db_table = 'problem'
class Test(models.Model):
testid = models.IntegerField(primary_key=True)
proid = models.IntegerField()
code = models.TextField()
timec = models.IntegerField(blank=True, null=True)
memoryc = models.IntegerField(blank=True, null=True)
result = models.CharField(max_length=20)
time = models.DateTimeField()
userid = models.IntegerField()
class Meta:
managed = False
db_table = 'test'
class User(models.Model):
userid = models.AutoField(primary_key=True)
account = models.CharField(unique=True, max_length=15)
key = models.CharField(max_length=20)
nickname = models.CharField(max_length=20, blank=True, null=True)
sex = models.CharField(max_length=2)
university = models.CharField(max_length=20, blank=True, null=True)
blog = models.CharField(max_length=100, blank=True, null=True)
isadmin = models.IntegerField(db_column='isAdmin') # Field name made lowercase.
desc = models.TextField(blank=True, null=True)
submitted = models.IntegerField()
accepted = models.IntegerField()
class Meta:
managed = False
db_table = 'user'
settings.py
"""
Django settings for SDUVJ project.
Generated by 'django-admin startproject' using Django 1.11.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '8m2b=_6id@3--a5c%6be$x6#_=@72x3x$--=9=n%w7*haggffj'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'SDUVJ.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'SDUVJ.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'vj',
'USER': 'vj',
'PASSWORD': '******',
'HOST':'211.87.227.207',
'PORT':'3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
4、完成了数据库到网页的显示
//TODO