signsys's Issues
update codes
SignSys\SignSys\urls.py
from SignModel import views as SignModel_views
from HttpDownloads import views as HttpDownloads_views
urlpatterns = [
url(r'^$', SignModel_views.sign),
url(r'^sign/', SignModel_views.sign),
url(r'^signfinish/', SignModel_views.signfinish),
url(r'^res/', HttpDownloads_views.download),
url(r'^admin/', admin.site.urls),
]
SignSys\HttpDownloads\views.py
from django.shortcuts import render
from django.http import HttpResponse, FileResponse
from django.utils.http import urlquote
import os
Create your views here.
def download(request):
file_name = request.GET.get('file', '')
try:
basedir = os.path.dirname(os.path.abspath(__name__))
full_path = basedir + '/Res/' + file_name
print(full_path)
file = open(full_path, 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
# response['Content-Disposition'] = 'attachment;filename=' + file_name#.encode('utf-8')
response['Content-Disposition'] = 'attachment;filename="%s"'%(urlquote(file_name))
return response
except Exception:
return HttpResponse("File not found.", status=404)
SignSys\SignSys\settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'SignModel',
'HttpDownloads',
]
add UX
- transfor to UTF-8
- {% load static %}
- background-image:url({% static "SignModel/Default_01.gif" %})
(https://docs.djangoproject.com/en/1.10/howto/static-files/) - add: input class="input" type="text" name="name"
suggestion: Content-Disposition inline
Content-Disposition属性有两种类型:inline 和 attachment inline :将文件内容直接显示在页面 attachment:弹出对话框让用户下载具体例子
form checking
views.py
from django.shortcuts import render
from SignModel.models import Course
from SignModel.models import Record
from django.http import HttpResponse
from SignModel.forms import check_form
Create your views here.
def sign(request):
course_list = list(Course.objects.all().order_by('name'))
return render(request, 'sign.html', {'course_list': course_list})
def signfinish(request):
#storage in database
if request.method == 'POST':
form = check_form(request.POST)
if form.is_valid():
name = request.POST.get("name")
grade = request.POST.get("grade_list")
courses = request.POST.getlist("courses")
phone_num = request.POST.get("phone_num")
email = request.POST.get("email")
(object, created) = Record.objects.get_or_create(name=name, grade=grade, phone_num=phone_num, email=email)
if created == True:
print(name, grade, courses, phone_num)
for c in courses:
obj = Course.objects.get(name=c)
object.course_list.add(obj)
object.save()
else:
print("The record is created.")
return render(request, 'signfinish.html')
else:
print("**** invalid!! ****")
return render(request, 'sign.html')
else:
return render(request, 'signfinish.html') #for weichat flow
forms.py
from django import forms
from django.core import validators
from SignModel.models import Record
class check_form(forms.Form):
phone_num = forms.CharField(validators=[validators.RegexValidator(r'^\d{3,11}$', message='请输入正确的电话号码')])
def clean_phone_num(self):
phone_num = self.cleaned_data.get('phone_num')
exists = Record.objects.filter(phone_num=phone_num).exists()
if exists:
raise forms.ValidationError(message='此电话号码已经被注册')
return phone_num
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.