Some useful Django API CRUD for backend development with Swagger for cool doc!
Plus AI-generated questions for Python&Django study!
Clone this repo:
git clone https://github.com/gobbez/DjangoAPIInstall requirements.txt:
cd API
pip install requirements.txt(optional, if you want to use Ollama to create questions)
ollama run gemma2
Create migrations:
python manage.py makemigrations
python manage.py migrateLaunch Django server:
python manage.py runserverRead the doc with every route and method on Swagger:
http://127.0.0.1:8000/swagger/Or in Redoc:
http://127.0.0.1:8000/redoc/Use Postman to do a Post request and enable Ollama to generate N questions about Python and Django!
- Create migrations and launch your server (python manage.py runserver)
- Open Postman and in the Body write a "times": int
- (if in local) use this url http://127.0.0.1:8000/addpythonquiz/
- Now Ollama will create N rows in the PythonQuiz table!
- Play Game *
- Use Postman (or browser) to send a GET request and start your study-game! This api call will pick a random question from the table
- In the Postman send a POST request with the body as a Json format with: { "quizmode": "true", "username": "YOUR_USERNAME", "quest_id": "QUESTION_ID", "answer": "YOUR_ANSWER", }
- This will enable you to play the game, and get a right or wrong answer (with points)
You can do different GET functions passing the "ask" param, I list them below:
- showusers = Show all Users table
- showtotquiz = Show the total quiz in the PythonQuiz table
- randomquiz = Get a random quiz from the PythonQuiz table, even those you have already answered
- newquiz = Get a random quiz that you haven't answered yet
- wrongquiz = Get a random quiz from those that you have it wrong
You can do different POST functions passing the "quizmode" param, I list them below:
- true = Enable the game. You can answer a question (use one of the above GET functions to see the question!). In this mode the answer will be saved in the right or wrong Users column to enable "newquiz" or "wrongquiz" GET functions.
- not true = Make Ollama create N questions in the PythonQuiz table (use "times" param to say how many questions to add!)
Enjoy!