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 <shubhipandey202000@gmail.com> wrote:
the error is:
django.core.exceptions.FieldError: Unknown field(s) (e-resource) specified for Post

models.py
class Post(models.Model):
    e_resource = models.FileField(null=True,
                           blank=True,
                           validators=[FileExtensionValidator( ['pdf'] ) ],upload_to='')

views.py
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
            cdform.save()
            return HttpResponse("File Uploaded successfully")
     else:
        form = PostForm()
     return render(request, 'uploadAttendance.html', {'form': form,'shop' : shop})

forms.py
class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ['e-resource']

No comments:

Post a Comment