Skip to content

Not working no post request #2

@anonmanx

Description

@anonmanx

So I was integrating this with my website but I am facing some problems, main problem is like no post request is getting through.

My views.py:

class PageDetailView(View): 
     def get(self, request,**kwargs):
	page = get_object_or_404(Page, pk=self.kwargs['pk'])
	photos_list = Photo.objects.all()
	stories = page.story_set.all()
	users = User.objects.filter(groups__name= page.name)

	context = {
			'page':page,
			'photos':photos_list,
	}

	return render(self.request, 'page/page_detail.html', context=context)


     def post(self, request):
	form = PhotoForm(request.POST, request.FILES)
	if form.is_valid():
		photo = form.save()
		data = {'is_valid': True, 'name': photo.file.name, 'url': photo.file.url}
	else:
		data = {'is_valid': False}
	return JsonResponse(data)``

urls.py :

path('<int:pk>/', PageDetailView.as_view(), name='page_detail'),

my template view:

<button type="button" class="btn btn-primary js-upload-photos">
  <span class="glyphicon glyphicon-cloud-upload"></span> Upload photos
</button>
<input id="fileupload" type="file" name="file" multiple
       style="display: none;"
       data-url="{% url 'page_detail' pk=page.pk %}"
       data-form-data='{"csrfmiddlewaretoken": "{{ csrf_token }}"}'>

I kind of think all the js and other things are getting imported. But when I click the Upload button, no post request is there and nothing happens. It just is a complete disaster. What can I do?
Would be really really helpful if you can provide any solutions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions