[portland] OS Bridge proposal date extended
python at dylanreinhardt.com
Thu Apr 2 08:37:19 CEST 2009
If I understand your issue correctly, you want to mix new content created
and managed by Django with legacy content that exists in the form of static
This is actually easier than it sounds. There are many possible solutions,
but here's one. Whether it is the right one will depend on how much of what
type of stuff you have.
So let's say you have a model you're using for content. And let's say you
want this model to represent a "page" whether that page is new (managed by
Django) or legacy (exists in file). That way both types of "page" can be
managed by the same views at similar URLs. If you want that content object
to do double duty, here's what you might do:
1. Add a FilePathField to your model. Docs:
2. Add a method to your model that returns the contents of the file at the
path specified in that field
3. In your template(s), check for the presence of a value in the
FilePathField. If it's there, just dump out the contents of the file. If
not, proceed to render your page as you normally would.
If you end up with images that use relative paths that are no longer valid,
you can probably fix those quickly with an entry in urls.py or an Apache
RewriteRule. Shouldn't take much to map any legacy paths to the new static
Anyway... hope that's helpful.
On Wed, Apr 1, 2009 at 10:59 PM, kirby urner <kirby.urner at gmail.com> wrote:
> Thanks Dylan, plus to those replying off list.
> I'm trying to wrap an old static HTML website in Django such that I
> don't have to change relative paths to images in subdirectories that
> won't really be there anymore. I'm wanting all URLs from the outside
> world to stay the same as well i.e. all the old links will work as is.
> http://www.4dsolutions.net/ocn/cp4e.html will now point to
> http://www.4dsolutions.net/controlroom/ocn/old/archive/cp4e.html under
> the hood, with the later containing <img src="graphics/pix.png"> tags
> that need to be statically served from controlroom/media/ocn/graphics
> -- that kind of thing.
> Kind of a hack maybe, an exercise. The idea is new content would take
> advantage of the framework more, but this is a way of grandfathering
> in what's at the site already, basically with no changes.
> On Wed, Apr 1, 2009 at 5:12 PM, Dylan Reinhardt
> <python at dylanreinhardt.com> wrote:
> > This might help:
> > http://docs.djangoproject.com/en/1.0/howto/static-files/
> > HTH,
> > Dylan
> > On Wed, Apr 1, 2009 at 4:59 PM, kirby urner <kirby.urner at gmail.com>
> >> Django is driving me nuts I have to admit. It's the static media bit.
> >> It's all on my Ubuntu laptop so if someone wants to show me where I'm
> >> going wrong, the bagels are on me... (I had it working but then
> >> decided to move directories around...). Write me off list maybe. I
> >> live near the Bagdad.
> >> Yeah, more Python talks would be good. I'm not altogether clear what
> >> the audience will be like but I think there's always room for "just
> >> the basics" i.e. a good old fashioned tutorial that doesn't go too
> >> fast. I know we're into test driven development but I think doctest
> >> is sufficient with noobs. Indeed, Python pedagogy is effective
> >> because interactive...
> >> I could see PPUG offering a standard once month free class with
> >> rotating presenter, then spin-off more advanced topic classes that fly
> >> when they fill, sort of Saturday Academy still. Having something like
> >> a fixed schedule for the free ones, then scrambling amongst ourselves
> >> to always have an instructor, would be a fun way to make PPUG a
> >> stronger glue maybe. Just a thought.
> >> Kirby
> >> _______________________________________________
> >> Portland mailing list
> >> Portland at python.org
> >> http://mail.python.org/mailman/listinfo/portland
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: <
> > _______________________________________________
> > Portland mailing list
> > Portland at python.org
> > http://mail.python.org/mailman/listinfo/portland
> Portland mailing list
> Portland at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Portland