pourquoi je n'arrive pas a delete le quizz : XHRDELETE
http://127.0.0.1:5000/quiz/api/v1.0/quiz/1
[HTTP/1.1 405 METHOD NOT ALLOWED 31ms]

Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

​



<script>
export default {
  data() {
    return {
      questionnaires: [],
      selectedQuestionnaire: null,
      title : 'Mes Questionnaires: ',
      name: '',


      selectedQuestionnaire: null,
      newQuestion: {
        title: '',
        type: 'Question simple',
        option1: '',
        option2: '',
      },
    }
  },
  methods: {

    openForm(questionnaire) {
      this.selectedQuestionnaire = questionnaire;
    },


    selectQuestionnaire(questionnaire) {
      fetch(`http://127.0.0.1:5000/quiz/api/v1.0/quiz/${questionnaire.id}/questions`)
        .then(response => response.json())
        .then(json => {
          console.log(json);
          this.selectedQuestionnaire = json;
          this.quizId = questionnaire.id;
        });
    },



    modif(question) {
      // ...
    },


    


    creerQuiz(name) {
      fetch('http://127.0.0.1:5000/quiz/api/v1.0/quiz', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ name: name }),
      })
      .then(response => response.json())
      .then(json => {
        console.log(json);
        this.fetchQuestionnaires();
      });
    },


    fetchQuestionnaires() {
      fetch('http://127.0.0.1:5000/quiz/api/v1.0/quiz')
        .then(response => response.json())
        .then(json => {
          this.questionnaires = json;
        });
    },


    supprimerQuestion(question) {
      fetch(`http://127.0.0.1:5000/quiz/api/v1.0/quiz/questions/${question.id}`, {
        method: 'DELETE',
      })
      .then(response => response.json())
      .then(json => {
        console.log(json);
        if (json.result) {
          this.selectedQuestionnaire = this.selectedQuestionnaire.filter(q => q.id !== question.id);
        }
      });
    },
    
    supprimerQuestionnaire(questionnaire) {
      console.log(questionnaire.id);
      fetch(`http://127.0.0.1:5000/quiz/api/v1.0/quiz/${questionnaire.id}`, {
        method: 'DELETE',
      })
      .then(response => response.json())
      .then(json => {
        console.log(json);
        if (json.result) {
          console.log(json.result)
          this.questionnaires = this.questionnaires.filter(q => q.id !== questionnaire.id);
        }
      });
    },











    // fonction a changer pour ajouter question a un questionnaire

    ajouterQuestion(questionnaire) {
      fetch(`http://127.0.0.1:5000/quiz/api/v1.0/quiz/<int:quiz_id>/questions`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          title: this.newQuestion.title,
          text: this.newQuestion.questionType,
          option1: this.newQuestion.option1,
          option2: this.newQuestion.option2,
          quizId: questionnaire.id,
        }),
      })
      .then(response => response.json())
      .then(json => {
        console.log(json);
        if (json.result) {
          this.selectedQuestionnaire.push(json.question);
        }
      });
      
      this.newQuestion = {
        title: '',
        text: '',
        option1: '',
        option2: '',
      };
      this.showForm = false;
    },







  },




  mounted() {
    this.fetchQuestionnaires();
  }
}
</script>




<template>
  <div>
    <h1>{{ title }}</h1>
    <h2>Creer un Quiz</h2>
    <input type="text" v-model="name" />
    <button @click="creerQuiz(name)">Creer Quiz</button>



    <!-- Modifier ici pour ajoute question a un questionnaire, pb affichage bizzare -->
    
    <ul>
      <li v-for="questionnaire in questionnaires" :key="questionnaire.id">
        {{ questionnaire.name }}
        <button @click="openForm(questionnaire)">Ajouter Question</button>
        <button @click="supprimerQuestionnaire(questionnaire)">Supprimer Questionnaire</button> 

        <div v-if="selectedQuestionnaire === questionnaire">
          <input type="text" v-model="newQuestion.title" placeholder="Title" />
          <select v-model="newQuestion.type">
            <option value="Question multiple">Question multiple</option>
            <option value="Question simple">Question simple</option>
          </select>
          <input type="text" v-model="newQuestion.option1" placeholder="Option 1" />
          <input v-if="newQuestion.type === 'Question multiple'" type="text" v-model="newQuestion.option2" placeholder="Option 2" />
          <button @click="ajouterQuestion">Submit</button>
        </div>

      </li>
    </ul>



    <div v-if="selectedQuestionnaire">
      <div v-for="question in selectedQuestionnaire" :key="question.id">
        <h2>Modifier la question {{ question.title }}</h2>
        <p>{{ question.questionType }}</p>
        <button @click="modif(question)">Modifier</button>
        <button @click="supprimerQuestion(question)">Supprimer</button>
      </div>
    </div>






  </div>
</template><script>
export default {
  data() {
    return {
      questionnaire: {},
      todoModif: true
    }
  },
  props: {
    questionnaire: Object
  },
  methods: {
    remove(questionnaire) {
      this.$emit('remove', this.questionnaire)
    },
    modifierItem(questionnaire) {
      this.todoModif = false
    },
    updateItem(questionnaire) {
      this.todoModif = true
      this.$emit('modifier', this.questionnaire)
    }
  },
  emits: ['remove', 'modifier']
}
</script>

<template>
  <div>
    <h1>{{ questionnaire.name }}</h1>
    <div class="checkbox">
      <input type="checkbox" id="checkbox" v-model="questionnaire.done">
      <label for="checkbox"></label>
    </div>
  </div>
</template>

<style scoped>
</style>from flask import jsonify , abort , make_response , request, url_for

from .app import app
from .models import *


@app.route('/quiz/api/v1.0/quiz', methods = ['GET'])
def get_quizs():
    return jsonify(get_list_quizs())

@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>', methods = ['GET'])
def get_quiz(quiz_id):
    return jsonify(get_quiz_by_id(quiz_id))


@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>/questions', methods = ['GET'])
def get_questions(quiz_id):
    question = get_questions_by_quiz_id(quiz_id)
    if question is not None:  
            return jsonify(question)
    else:
        abort(404)

@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>/questions/<int:question_id>', methods = ['GET'])
def get_question(quiz_id, question_id):
    question = get_question_by_quiz_id_question(quiz_id,question_id)
    if question is not None:  
            return jsonify(question)
    else:
        abort(404)





@app. errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)

@app. errorhandler(400)
def not_found(error):
    return make_response(jsonify({'error': 'Bad request'}), 400)







@app.route('/quiz/api/v1.0/quiz', methods = ['POST'])
def create_quiz():
    if not request.json or not 'name' in request.json:
        abort(400)
    return add_quiz(request.json['name']).to_json()



@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>/questions', methods = ['POST'])
def create_question(quiz_id):
    if not request.json or not 'title' in request.json or not 'questionType' in request.json:
        abort(400)
    return add_question(quiz_id,request.json).to_json()







@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>', methods = ['PUT'])
def update_quiz(quiz_id):
    quiz = [get_quiz_by_id(quiz_id)]
    if len(quiz) == 0:
        abort(404)
    if not request.json:
        abort(400)
    if 'name' in request.json and type(request.json['name']) != str:
        abort(400)
    update_quiz_name(quiz_id, request.json.get('name', quiz[0]['name']))
    quiz[0]['name'] = request.json.get('name', quiz[0]['name'])
    return jsonify({'quiz': quiz[0]})






@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>', methods = ['DELETE'])
def delete_task(quiz_id):
    quiz = [get_quiz_by_id(quiz_id)]
    if len(quiz) == 0:
        abort(404)
    del_quiz(quiz_id)
    return jsonify({'result': True})









@app.route('/quiz/api/v1.0/quiz/<int:quiz_id>/questions/<int:question_id>', methods = ['PUT'])
def update_question(quiz_id, question_id,):
    if not request.json or not 'title' in request.json or not 'questionType' in request.json:
        abort(400)
    question = [get_questions_by_question_id(question_id)]
    if len(question) == 0:
        abort(404)

    return jsonify(update_questionn( question_id,request.json))


@app.route('/quiz/api/v1.0/quiz/questions/<int:question_id>', methods = ['DELETE'])
def delete_question(question_id):
    question = [get_questions_by_question_id(question_id)]
    if len(question) == 0:
        abort(404)
    del_question(question_id)
    return jsonify({'result': True})