Server Setup
Before start make sure you have followed all steps in the installation guide and have your environment activated.
Create main.py
Create a new file called main.py in your project folder. This file will be the entry point of your server.
Import the nerfw package.
import nerfw
In the end of the file, add the following code.
import nerfw
if __name__ == "__main__":
"""Your code here"""
This is done to prevent the code from running when the file is imported as a module. It is a good practice in python to have this part in your main file due to the way python handles imports.
Create a server
Under the if __name__ == "__main__": line, create a instance of NerFW class.
import nerfw
if __name__ == "__main__":
server = nerfw.NerFW()
This will create a server instance with default settings.
Server settings
Debug or Production mode
You can set the server to run in debug mode by setting the
debugparameter toTruewhen creating the server instance.server = nerfw.NerFW(debug=True)
This will enable the debug mode, which will show you detailed error messages and stack traces in the browser. This mode is enabled by default. To switch to a production mode, set the
debugparameter toFalse.server = nerfw.NerFW(debug=False)
Set name of the server
You can set the name of the server by setting the
nameparameter when creating the server instance.server.set_name("MyServer")
This will set the name of the server to
MyServer.Set login method
You can set the login method by setting the
login_methodparameter when creating the server instance.server.set_login_method("default")
This will set the login method to
default. The available login methods aredefault,githubandpatreon.We will cover the GitHub and Patreon login methods in the next section since they require additional actions. Default login does not.
Set allowed users
With
DefaultorGitHubselected you can provide a list of allowed users. You can either provide a list of usernames or path to a file containing usernames.server.set_allowed_users(["user1", "user2"])
or
server.set_allowed_users("path/to/file.txt")
Set menu background
In NerFW you can set a background image for the menu. You can do this by calling the
set_menu_backgroundmethod. This method takes the path to the image as a parameter.server.set_menu_background("path/to/image.jpg")