url.py
from django.conf.urls import patterns, include, url from django.contrib import admin from main.views import * #from statistics.views import * from django.contrib.auth import views
from django.contrib.auth.views import login, logout
#from log.forms import LoginForm
#from django.contrib.auth.views import login, logout
#admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'IR.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
#url(r'^$', index),
#url(r'^IntroIR/', IntroIR),
url(r'^stu_auth/', stu_auth),
url(r'^stu_notice/', stu_notice),
url(r'^stu_record/', stu_record),
#url(r'^Resource/', Resource),
#url(r'^test/', base),
)
Views.py
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.template import RequestContext
from main.models import *
from django.contrib import auth
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
#from views import index
#from django.contrib.auth.views import login, logout
import json
import requests
#import xml.etree.cElementTree as ET
def stu_auth(request):
if 'student_id' in request.GET and request.GET['student_id']:
r1 = Record.objects.create(student_id = request.GET['student_id'])
#register = Register.objects.filter(validate=False)
return render_to_response('se_test.html', locals())
else:
return render_to_response('test.html', locals())
def stu_notice(request):
r2 = Record.objects.get(student_id = request.GET['student_id'])
#register = Register.objects.filter(validate=False)
return render_to_response('th_test.html', locals())
def stu_record(request):
# register = Register.objects.filter(validate=False)
f_key =request.FILES['r_keyboard']
with open('./media/keyboard/'+name+'.doc', 'w') as destination:
for chunk in f.chunks():
destination.write(chunk)
return render_to_response('th_test.html', context_instance=RequestContext(request))
setting.py
"""
Django settings for ADDP project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '1x2d0i1jl#o8ykz+-+#bvfoq(lj02ma@mc*omzt8j=ka(osz7)'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_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',
'main',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'ADDP.urls'
WSGI_APPLICATION = 'ADDP.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'zh-TW'
TIME_ZONE = 'Asia/Taipei'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = (
os.path.join(BASE_DIR, "locale"),
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.core.context_processors.csrf',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages'
)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)