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
The best practice suggests using forward slashes, even while on Windows. An even better practice would be to use the build in os module to join paths together. This technique is also OS independent since it knows to use the correct directory separator. Furthermore, it's a part of the Python standard library and Django even sets up a BASE_DIR variable in your settings automatically when creating a project.
In your settings.py:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)importosBASE_DIR=os.path.dirname(os.path.dirname(__file__))
STATICFILES_DIRS= [
os.path.join(BASE_DIR, 'static'),
# etc...
]
The text was updated successfully, but these errors were encountered:
I might point out that even your 'best practices' window uses backslashes in the example (cut/paste problem?) instead of the correct forward slashes...
And furthermore, the anti-pattern doesn't escape the backslashes or use a raw string, which means that the actual string object doesn't have backslashes in it.
The best practice suggests using forward slashes, even while on Windows. An even better practice would be to use the build in
os
module to join paths together. This technique is also OS independent since it knows to use the correct directory separator. Furthermore, it's a part of the Python standard library and Django even sets up aBASE_DIR
variable in your settings automatically when creating a project.In your settings.py:
The text was updated successfully, but these errors were encountered: