Opened 3 years ago
Closed 3 years ago
#34185 closed Uncategorized (invalid)
Serving static/media files during development can't work when use SCRIPT_NAME
| Reported by: | YQ | Owned by: | nobody | 
|---|---|---|---|
| Component: | Documentation | Version: | 4.1 | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description (last modified by )
The Documentation:
https://docs.djangoproject.com/en/4.1/howto/static-files/#serving-static-files-during-development
urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
My SCRIPT_NAME is '/django'
Page not found problem when access the static files:(the debug info)
Page not found (404) Request Method: GET Request URL: http://www.abc.xyz/django/static/appdl/bulma/bulma.0.9.4.min.css Raised by: django.views.static.serve Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: [name='index'] appdl/ admin/ ^django/static/(?P<path>.*)$ ^django/media/(?P<path>.*)$ The current path, static/appdl/bulma/bulma.0.9.4.min.css, didn’t match any of these.
Prefix 'django' shouldn't  In url patterns.
So, this code should be replaced:
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to
static('static/', document_root=settings.STATIC_ROOT)
because the  'settings.STATIC_URL' added SCRIPT_NAME  as prefix.
Change History (2)
comment:1 by , 3 years ago
| Description: | modified (diff) | 
|---|
comment:2 by , 3 years ago
| Resolution: | → invalid | 
|---|---|
| Status: | new → closed | 
  Note:
 See   TracTickets
 for help on using tickets.
    
Did you see the note about this topic in the STATIC_URL docs? https://docs.djangoproject.com/en/4.1/ref/settings/#static-url
Please see TicketClosingReasons/UseSupportChannels for places to get usage advice.