Thursday, March 23, 2023

Re: Help in django. I want to upload files

Your field is called e_resource with an underscore but you're trying to reference it using a dash.

On March 22, 2023 11:40:00 PM CDT, Shubhi Pandey <> wrote:
the error is:
django.core.exceptions.FieldError: Unknown field(s) (e-resource) specified for Post
class Post(models.Model):
    e_resource = models.FileField(null=True,
                           validators=[FileExtensionValidator( ['pdf'] ) ],upload_to='')
def uploadResource_details(request,shop):
     shop = workshop_details.objects.get(w_id=shop)
     if request.method == 'POST':
        form = PostForm(request.POST, request.FILES)
        if form.is_valid():
            cdform = form.cleaned_data
            return HttpResponse("File Uploaded successfully")
        form = PostForm()
     return render(request, 'uploadAttendance.html', {'form': form,'shop' : shop})
class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ['e-resource']

No comments:

Post a Comment