'How can I make a simple website that changes content each time it's refreshed?

I understand this question could be more specific, though I'm hoping someone can point me in the right direction when it comes to creation a simple website that services different content on the same URL each time it's refreshed.

As example of what I mean by this can be found here:

http://www.whatthefuckshouldimakefordinner.com/

From what I understand, I will need to do something like the following:

  1. Build the HTML/CSS (I can do this)
  2. Create a database of content (I can do this)
  3. Serve the content (I'm not exactly sure how to do this if it's changes each time the website is refreshed).

Thanks



Solution 1:[1]

I have no clue how databases work with html, but in theory you can do something like this:


<body>
    <script>
    arrayOfText= ["stuff","from","database","...","extra", "extra stuff", "more", "more stuff"];

    randomNumber = Math.floor(Math.random() * arrayOfText.length);
    textToPutOnSite = arrayOfText[randomNumber];
    console.log(textToPutOnSite);
    </script>
</body>

Solution 2:[2]

You have to use some kind of web framework I recommend flask for python because it is easy to use but still powerful. flask's website

If you really want something advanced you can use Django, but it is really advanced, and I'm not sure if you really need that, the good thing with Django is the fact that it comes with a database all integrated. Django's website

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 rafalou38