def contact request if request method POST form ContactForm request PO

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST,request.FILES)
if form.is_valid():
form.save()
# Do form processing here...
subject = request.POST['subject']
message = request.POST['message']
sender = request.POST['sender']
if request.FILES:
os.mkdir("/home/offline/django/muzx/static/users/"+request.user.username)
f = file( "/home/offline/django/muzx/static/users/" + request.user.username + "/" + str(int(time.time())) + '.jpg', "w" )
f.write(form.cleaned_data['image'].content)
f.close()
image = form.cleaned_data['image'].filename
else:
image = ''
return render_to_response('detail.html',{'subject':subject,'message':message,'sender':sender,'image':image})
else:
form = ContactForm(auto_id='my_id_%s')
return render_to_response('detail.html', {'form': form,'path':path,'hello':hello})