Examination module based on Django website development part I

InfoQ 2022-05-14 14:32:05 阅读数:322


One , Preface

There's a need :

You are very good : Give me a dump ctf Development tasks come here . What can only be a little : Let's develop the exercises first , We can do problems on Niuke .

This demand may be difficult for me two months ago , Now it's basically no difficulty for me . It took two days to take a basic look at the architecture 【 Because this is the first time to get all the source code 】 And adapted to the style of the examination section .

Two , Design logic

Since it's an examination module , There must be a lot of papers . Of course you can't write a bunch on the main page, can you , I designed a database to store the basic information of the test paper , Traverse the output at the front end .PS: This part was designed two months ago .

On the back end sql Database processing , Turn into python Object dictionary set , Traverse the output to the front end .

Yesterday, I designed the database of corresponding topics : The answer board is very similar to that of Niuke , The title is JavaScript Variable , Old acquaintance . I preliminarily designed the topic that should be stored + Options + answer + identification id.

Logic of thinking : Rely on... At the front end in the early stage :

<a href=&quot;{% url 'middle' %}?keyjobs={{a.id}}&quot; >

Back end get To the identification of the test paper . Put it in a variable , To be used . use a Label transmission ,get


Then there is the linked database , Write a sql Tone , Processing data .

for var in results:

Do it sql Take out the data in the database , Convert to the dictionary set we need . Then loop and append to the list .


The next step is to pass the value to the front end . Turn into json In the form of ,js Accept .

var data={{ question_list| safe }};

Optimized the previous basic structure , Removed a series of routes , Replace all pages with one page . The current view layer is as follows :

 path('middle/', views.middle,name=&quot;middle&quot;)

3、 ... and , Database design

Question number , Question title , Question options , The answer to the question , identification 【 Keep it 】.

adopt , The back-end statement processes the database , Extract it and convert it into json Pass it to the front end .

ok, Today, I caught a java Homework , It's true. I don't want to write articles in typing , Take a minute today , Make up for the next article tomorrow .

watch python Of imustctf Code , Change your mind , Write java The experiment is a little short circuited ...

版权声明:本文为[InfoQ]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/134/202205141424380671.html