|
2 | 2 |
|
3 | 3 | from django.contrib.staticfiles.finders import find
|
4 | 4 | from django.core.checks import Error, Tags, Warning, register
|
| 5 | +from django.template import loader |
5 | 6 |
|
6 | 7 |
|
7 | 8 | @register(Tags.compatibility)
|
@@ -48,7 +49,7 @@ def reactpy_warnings(app_configs, **kwargs):
|
48 | 49 | if (
|
49 | 50 | sys.argv
|
50 | 51 | and sys.argv[0].endswith("daphne")
|
51 |
| - and getattr(settings, "REACTPY_BACKHAUL_THREAD", True) |
| 52 | + and getattr(settings, "REACTPY_BACKHAUL_THREAD", False) |
52 | 53 | and sys.platform == "linux"
|
53 | 54 | ):
|
54 | 55 | warnings.append(
|
@@ -76,11 +77,47 @@ def reactpy_warnings(app_configs, **kwargs):
|
76 | 77 | Warning(
|
77 | 78 | "ReactPy failed to register the following components:\n\t+ "
|
78 | 79 | + "\n\t+ ".join(REACTPY_FAILED_COMPONENTS),
|
79 |
| - hint="Check if these paths are valid, or if an exception is being raised during import.", |
| 80 | + hint="Check if these paths are valid, or if an exception is being " |
| 81 | + "raised during import.", |
80 | 82 | id="reactpy_django.W005",
|
81 | 83 | )
|
82 | 84 | )
|
83 | 85 |
|
| 86 | + # Check if the reactpy/component.html template exists |
| 87 | + try: |
| 88 | + loader.get_template("reactpy/component.html") |
| 89 | + except Exception: |
| 90 | + warnings.append( |
| 91 | + Warning( |
| 92 | + "ReactPy HTML templates could not be found!", |
| 93 | + hint="Check your settings.py:TEMPLATES configuration and make sure " |
| 94 | + "ReactPy-Django is installed properly.", |
| 95 | + id="reactpy_django.W006", |
| 96 | + ) |
| 97 | + ) |
| 98 | + |
| 99 | + # Check if REACTPY_WEBSOCKET_URL doesn't end with a slash |
| 100 | + REACTPY_WEBSOCKET_URL = getattr(settings, "REACTPY_WEBSOCKET_URL", "") |
| 101 | + if isinstance(REACTPY_WEBSOCKET_URL, str): |
| 102 | + if not REACTPY_WEBSOCKET_URL or not REACTPY_WEBSOCKET_URL.endswith("/"): |
| 103 | + warnings.append( |
| 104 | + Warning( |
| 105 | + "REACTPY_WEBSOCKET_URL did not end with a forward slash.", |
| 106 | + hint="Change your URL to be written in the following format: 'example_url/'", |
| 107 | + id="reactpy_django.W007", |
| 108 | + ) |
| 109 | + ) |
| 110 | + |
| 111 | + # Check if REACTPY_WEBSOCKET_URL doesn't start with an alphanumeric character |
| 112 | + if not REACTPY_WEBSOCKET_URL or not REACTPY_WEBSOCKET_URL[0].isalnum(): |
| 113 | + warnings.append( |
| 114 | + Warning( |
| 115 | + "REACTPY_WEBSOCKET_URL did not start with an alphanumeric character.", |
| 116 | + hint="Change your URL to be written in the following format: 'example_url/'", |
| 117 | + id="reactpy_django.W008", |
| 118 | + ) |
| 119 | + ) |
| 120 | + |
84 | 121 | return warnings
|
85 | 122 |
|
86 | 123 |
|
|
0 commit comments