Advertisement
avaaren

Url not found

Apr 7th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. Not Found: /ajax_result/
  2. [07/Apr/2020 12:48:14] "POST /ajax_result/ HTTP/1.1" 404 1742
  3.  
  4.  
  5. НО
  6. в урлс:
  7. path('ajax_result/', views.AjaxResultView.as_view(), name='ajax_result'),
  8.  
  9. во вьювс:
  10. class AjaxResultView(View):
  11.  
  12.     def post(self, request):
  13.  
  14.         user = request.user
  15.         user_profile = get_object_or_404(Profile, user=user)
  16.         score = request.POST.get('result')
  17.         if score:
  18.             # Create object of game
  19.             GameSession.objects.create(
  20.                 user=user,
  21.                 score=score
  22.             )
  23.             # Update user info
  24.             user_profile.update(games_played=F('games_played') + 1)
  25.             if score > user_profile.high_score:
  26.                 user_profile.update(high_score=score)
  27.             # Showing result
  28.        
  29.             data = {
  30.                 'is_success': True,
  31.             }
  32.             redirect(ResultView)
  33.         return JsonResponse(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement