Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working no post request #2

Open
anonmanx opened this issue Feb 5, 2020 · 0 comments
Open

Not working no post request #2

anonmanx opened this issue Feb 5, 2020 · 0 comments

Comments

@anonmanx
Copy link

anonmanx commented Feb 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant