社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

关于django 文件上传的问题,求指教

andy19940630 • 10 年前 • 2386 次点击  

在实验文件上传的时候出现:

DatabaseError at /blog/upload/ table blog_music has no column named musicname Request Method: POST Request URL: http://127.0.0.1:8000/blog/upload/ Django Version: 1.5.8 Exception Type: DatabaseError Exception Value: table blog_music has no column named musicname Exception Location: C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 362 Python Executable: C:\Python27\python.exe Python Version: 2.7.9 Python Path: ['C:\out\mysite2', 'C:\Windows\SYSTEM32\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages'] Server time: Thu, 11 Jun 2015 14:41:47 +0800 的错误提示

在下是小白一枚,需要解救 view.py

from django import template from django.template import loader, Context from django.http import HttpResponse from blog.models import BlogPost,musicForm from django.http.response import HttpResponseRedirect from django.shortcuts import render def archive(request): latest_BlogPost_list=BlogPost.objects.order_by('-times')[:3] t=loader.get_template("archive.html") c=Context({'latest_BlogPost_list':latest_BlogPost_list}) return HttpResponse(t.render(c)) def upload_file(request): if request.method=='POST': form=musicForm(request.POST,request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect('ok.html') else: form=musicForm() return render(request,'upload.html',{'form':form})

html

<style type="text/css"> body { background-color: #396; } </style> <form enctype="multipart/form-data"method="POST"action=".\upload\"> {% csrf_token %} {{form.as_p}} <input type="submit" name="submit" value="ok"/> <input type="reset" name="reset" value="reset"> input music information

<img src="../static/images/t0117eeada0134f7954.jpg" width="240" height="240" />

model.py

from django.db import models from django.contrib import admin from django import forms

class BlogPost(models.Model): title=models.CharField(max_length=150) body=models.TextField() times=models.DateTimeField()

class BlogPostAdmin(admin.ModelAdmin): list_display=('title','times')

admin.site.register(BlogPost, BlogPostAdmin)

class music(models.Model): musicname=models.CharField(max_length=10)
musicauthor=models.CharField(max_length=10)
musicspecial=models.CharField(max_length=10) class musicForm(forms.ModelForm): file=forms.FileField() class Meta: model=music

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1126
 
2386 次点击