from __future__ import unicode_literals
from django.db import models
# Create your models here.
# User CLass for user,username and userimg path
class NormalUser(models.Model):
username = models.CharField(max_length=30)
headImg = models.FileField(upload_to='./upload')
def __unicode__(self):
return self.username
class Meta:
ordering = ['username']
from django.shortcuts import render,render_to_response
from django import forms
from django.http import HttpResponse
from app.models import *
# Create your views here.
class NormalUserForm(forms.Form):
username = forms.CharField()
headImg = forms.FileField()
def registerNormalUser(request):
if request.method == "POST":
uf = NormalUserForm(request.POST,request.FILES)
if uf.is_valid():
# get the info of the form
username = uf.cleaned_data['username']
headImg = uf.cleaned_data['headImg']
# write in database
normalUser = NormalUser()
normalUser.username = username
normalUser.headImg = headImg
normalUser.save()
return HttpResponse('Upload Succeed!')
else:
uf = NormalUserForm()
return render(request,'register.html',{'uf':uf})
"""Django_upload URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from app.views import *
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^register/$',registerNormalUser),
]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<h2 align="center">Register</h2>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ uf.as_p }}
<input type="submit" value="Submit">
</form>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有