In the DanceConnect folder, run: python -m venv .venv
source .venv/bin/activate
.venv/Scripts/activate
pip install -r requirements.txt
python main.py
<script src="https://cdn.ckeditor.com/ckeditor5/41.3.1/classic/ckeditor.js"></script>
<textarea>
or <div>
in the HTML with a unique id.editor-id
with id of element from step 2):
items
is the list of toolbar features that the user can useremovedItems
are disabled|
is used to separate elements in the toolbar UI into groups
ClassicEditor.create(document.getElementById(editor-id), {
toolbar: {
items: [
'undo', 'redo',
'|', 'heading',
'|', 'bold', 'italic', 'link',
'|', 'bulletedList', 'numberedList', 'outdent', 'indent',
'|',
],
removeItems: ['uploadImage', 'blockQuote', 'mediaEmbed', 'insertTable'],
}
});
### Retrieving User Input
4. Get user input from the `<div>` or `<textarea>` as you normally would using. (Only tried with `<textarea>` so far).
5. Sanitize html input by importing the `sanitize_html` method from `\website\__init__.py`.
- Note: This basically whitelists a set of acceptable HTML elements and escapes everything else. It works for the config example in step 3, but if additional toolbar items are enabled, you would can pass a list of tags into `additional_tags` to enable them. Ex: `sanitize_html(html_input, ['img', 'br'])`
- Note 2: Probably best to use as few tags as possible for better security.
6. To validate the input before it is submitted (e.g. making a field required):
- Load JQuery Validation from CDN: `<script src="https://cdn.ckeditor.com/ckeditor5/41.3.1/classic/ckeditor.js"></script>`
- Configure the validator in JS:
$("form").validate({
ignore: [],
rules: {
input1_name_attribute: { required: true },
input2_name_attribute: {
required: true,
minlength: 5,
},
...
},
messages: {
input1_name_attribute: "This field is mandatory",
input2_name_attribute: {
required: "This field is mandatory.",
minlength: "This field must have at least 5 characters.",
},
...
}
})
```
- `rules` specify how to validate the input
- `messages` are the error messages the user sees if validation on any field fails
|safe
to tell Jinja that this HTML code is safe to be rendered:
{{ variable_containing_html|safe }}
Setting up a web app on PythonAnywhere using an existing GitHub project involves a series of steps. Here’s a general process to get your web app running:
Before you start, you need an account on PythonAnywhere. If you don’t have one, you can sign up at PythonAnywhere's website.
Once logged in:
You can clone your repository directly into your PythonAnywhere account using the "Consoles" tab:
/home/yourusername
.git clone https://github.com/yourusername/yourrepository.git
It's a good practice to create a virtual environment for your project:
cd yourrepository
mkvirtualenv --python=/usr/bin/python3.8 myenv # Use appropriate Python version
workon myenv
Install any dependencies your project might have using pip. If your project includes a requirements.txt
file, you can install all dependencies with:
pip install -r requirements.txt
PythonAnywhere uses a WSGI file to serve your web app:
sys.path
to include your project directory and set the application callable. This depends on whether you’re using Flask, Django, or another framework.After configuring your WSGI file:
Visit your .pythonanywhere.com domain to see if your app is running correctly. If there are issues, check the "Error log" in the "Web" tab for clues.
You might need to return to the Bash console or the WSGI configuration and make adjustments based on the feedback from error logs or the behavior of your app.
This is a basic guide, and depending on the specific needs of your project or the framework you are using, some steps might differ. For instance, Django projects will need settings for static and media files, while Flask might be simpler but require specific app configurations.