Code

Opened 2 years ago

Closed 2 years ago

#17857 closed Bug (fixed)

CachedFilesMixin url_converter creates unnecessarily absolute urls

Reported by: tgecho Owned by: nobody
Component: contrib.staticfiles Version: master
Severity: Normal Keywords:
Cc: kmike84@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The url converter outputs absolute urls, even if they were originally defined as relative. If I do a collectstatic while DEBUG=True, it uses my local dev STATIC_URL.

So url("../img/shadow.png") becomes url("/static/img/shadow.96b0bd7b6268.png")

Only my production STATIC_URL is 'http://mystatic.s3.amazonaws.com/' so this link is broken when DEBUG=False

That's just a symptom of the problem that the url converter bakes in whatever STATIC_URL is in effect when collectstatic is run. If the final result was a relative path, then it would work wherever the static files ended up living. So ideally url("../img/shadow.png") becomes url(".../img/shadow.96b0bd7b6268.png"). This file would be portable no matter what the STATIC_URL is set to.

Attachments (1)

patch.diff (7.5 KB) - added by tgecho 2 years ago.

Download all attachments as: .zip

Change History (4)

Changed 2 years ago by tgecho

comment:1 Changed 2 years ago by tgecho

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 years ago by kmike

  • Cc kmike84@… added

comment:3 Changed 2 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [17697]:

Fixed #17857 -- Stopped CachedStaticFilesStorage from creating absolute URLs unnecessarily. Thanks, tgecho.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.