You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code-image-generator/README.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,3 +39,30 @@ Finally, run the Flask development server
39
39
```
40
40
41
41
Now you can navigate to the address that's shown in the output when you start the server. Commonly, that's `http://localhost:5000/`.
42
+
43
+
## Secret Key
44
+
45
+
If you want to deploy your Flask app later, then it's a good idea to generate a proper secret key.
46
+
47
+
If you need to create cryptographically sound data like a Flask secret key, then you can use Python's [`secrets`](https://docs.python.org/3/library/secrets.html) module:
48
+
49
+
```pycon
50
+
>>> import secrets
51
+
>>> secrets.token_hex()
52
+
'2e9ac41b1e0b66a8d93d66400e2300c4b4c2953f'
53
+
```
54
+
55
+
The `.token_hex()` method returns a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) string containing random numbers and letters from `0` to `9` and `a` to `f`. Use the value that `secrets.token_hex()` outputs for you and add it in your Flask project's `app.py` file:
To not save the secret key directly in your code, it may be a good idea to work with [environment variables](https://12factor.net/config). You can learn more about it in the Flask documentation about [Configuration Handling](https://flask.palletsprojects.com/en/2.3.x/config/).
0 commit comments