1) I did some tests with a django project and, my web pages look ugly
because the reference to .css files was lost, additionally I can not
retrieve the content of static files when a click on a certain link. It
seems that Aspen needs a reference to these resources. I had a similar
problem using Apache but I solved with next instrucctions:
Alias /media c:\django\django\contrib\admin\media
Alias /attached c:\project\application\attached
How can I do something like that in Aspen? Django has some indications
about that in:
http://www.djangoproject.com/documentation/static_files/
and there is a relationship with variables MEDIA_ROOT and MEDIA_URL
contained in settings.py, althought Apache does not need MEDIA_ROOT.
2) The .pdf manual has a little problem in the 5.2 section
(configuration file). Some words were clipped at end of the line. There
are some other sections with this problem also.
Your work looks nice.
Thanks and regards,
> 1) I did some tests with a django project and, my web pages look ugly
> because the reference to .css files was lost, additionally I can not
> retrieve the content of static files when a click on a certain link. It
>
> seems that Aspen needs a reference to these resources. I had a similar
>
> problem using Apache but I solved with next instrucctions:
> Alias /media c:\django\django\contrib\admin\media
> Alias /attached c:\project\application\attached
> How can I do something like that in Aspen? Django has some indications
> about that in:
> http://www.djangoproject.com/documentation/static_files/
> and there is a relationship with variables MEDIA_ROOT and MEDIA_URL
> contained in settings.py, althought Apache does not need MEDIA_ROOT.
This is helpful info, thanks! I'll need to dig into MEDIA_URL and
MEDIA_ROOT, as I believe these probably can/ought to be supported
automatically by Stephane. Can I get back to you here (if no-one
else has an answer)?
> 2) The .pdf manual has a little problem in the 5.2 section
> (configuration file). Some words were clipped at end of the line. There
> are some other sections with this problem also.
Thanks. Looks like I'll have to dig deeper into the glorious mess
that is the Python documentation system. :)
chad
There may be more than Aspen affecting the serving of static content.
It all depends upon how the user has set up things. For example, you
can configure django to serve up static content, but that is not
recommended for any kind of production setting. So you would normally
configure Apache (or whatever) to serve up the static media for you.
Aspen is using CherryPy's wsgiserver to serve Django. But it is my
understanding that the wsgiserver part of CherryPy is not for serving
static content directly unless you plug in a wsgi component that does
that.
In my experiments I had to run the CherryPy server directly to serve
*both* Django and static content. Here is a simplified example:
#!/usr/bin/python
import sys
import os
import cherrypy
from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler
os.environ["DJANGO_SETTINGS_MODULE"] = "djangotest.settings"
class DjangoApp(object):
_cp_config = {
'tools.wsgiapp.on': True,
'tools.wsgiapp.app': AdminMediaHandler(WSGIHandler()),
}
django_conf = {
'/test1/media' : {
'tools.staticdir.on' : True,
'tools.staticdir.root' :
os.path.abspath(os.path.join(os.path.dirname(__file__),'djangotest','test1')),
'tools.staticdir.dir' : 'media',
}
}
if __name__ == '__main__':
conf = os.path.join(os.path.dirname(__file__), 'pieserver.conf')
cherrypy.config.update(conf)
cherrypy.tree.mount(DjangoApp(),'/',django_conf)
cherrypy.server.quickstart()
cherrypy.engine.start()
--gordy
Thanks for jumping in!
> There may be more than Aspen affecting the serving of static content.
> It all depends upon how the user has set up things. For example, you
> can configure django to serve up static content, but that is not
> recommended for any kind of production setting. So you would normally
> configure Apache (or whatever) to serve up the static media for you.
Right, I would need to dig into that more to fully understand it.
> Aspen is using CherryPy's wsgiserver to serve Django. But it is my
> understanding that the wsgiserver part of CherryPy is not for serving
> static content directly unless you plug in a wsgi component that does
> that.
Aspen bundles just such a static WSGI component. We need to
document these components in a future release.
> In my experiments I had to run the CherryPy server directly to serve
> *both* Django and static content.
Ugh, sorry for the gymnastics! Turns out you can do this pretty
easily by wrapping Aspen's bundled static "handler" into an Aspen
"application." I've implemented this in r149 on the trunk:
http://aspen.googlecode.com/svn/trunk/src/aspen/apps/static.py
Note that you'll also need the find_default function in utils,
which got factored out of website.py in this revision as well:
http://aspen.googlecode.com/svn/trunk/src/aspen/utils.py
There's a few unit tests for find_default, but none yet for
apps.static (apparently working here, though).
With that code in place, you would wire it up like this in
__/etc/apps.conf:
/ grappelli:django
/changeme/static aspen.apps.static:static
Any default docs will apply, but there won't be an autoindex. For
that, see this bug:
http://code.google.com/p/aspen/issues/detail?id=85
Anyway, give that a shot if you like.
chad
I've installed the latest Aspen from here:
http://aspen.googlecode.com/svn/trunk
And then setup stephane as follows:
apps.conf:
/ grappelli:django # see __/lib/python2.x/grappelli.py
/test1/media aspen.apps.static:static
aspen.conf:
[django]
settings_module = djangotest.settings
I started aspen and tried this URL in the browser:
This correctly loaded my small test django application. Perfect!
Now on that page that loads, in addition to displaying some content
from the database model, it has links to do the following three things:
1. show a static media file from this URL:
http://localhost:8080/test1/media/sample.jpg
2. load the Django admin site from this URL:
3. dynamically generate a PDF document (using reportlab) from this URL:
http://localhost:8080/test1/pdf/
I noticed that aspen automatically created the directory structure
test1/media, with a helpful information file in the media directory.
All I had to do was delete the media directory that aspen created and
replace it with a symbolic link to the directory in my django app
structure, in this case it was located here:
djangotest/test1/media
That got item 1 from the list above working.
Now, to get item 2 working, I had to make a small edit to the
grapelli.py file, as follows:
Add this import at the top:
from django.core.servers.basehttp import AdminMediaHandler
And update this line at the bottom:
django = AdminMediaHandler(WSGIHandler())
That brought the admin site online.
Item 3 - the dynamic PDF generation is not quite working yet. My guess
is that the application/pdf mime type is not being recognized
correctly. Here is the code from the views.py in the test1 application
that generates the small PDF document:
from models import *
from cStringIO import StringIO
from django.http import HttpResponse
from reportlab.platypus import *
from reportlab.lib.pagesizes import LETTER
from reportlab.lib.units import inch
from reportlab.lib.styles import *
def gen_pdf(request):
response = HttpResponse(mimetype='application/pdf')
buffer = StringIO()
styles = getSampleStyleSheet()
doc = SimpleDocTemplate(buffer,pagesize=LETTER)
story = []
for c in Customer.objects.all():
story.append(Paragraph(c.name,styles['Normal']))
doc.build(story)
response.write(buffer.getvalue())
buffer.close()
return response
But anyway, aside from the PDF content, everything is working! A
couple of small suggestions:
1. I would add an option in the apps.conf file that would let the user
decide if they wanted support for the Django admin site or not. By
default, it would be exactly as you are doing now in the grappelli.py
file. If they enable that option then you just return the WSGIHandler
wrapped inside the AdminMediaHandler.
2. I would add an option for serving static media that would let you
map the URL for the location of the static media to a different place
in the file system. But that is not a critical issue by any means. It
may be better just to keep it the way that it is right now.
Chad thanks for all you work on this. I'm going to do some
benchmarking now! :-)
--gordy
Thanks for your continued experimentation, this is great!
> I noticed that aspen automatically created the directory structure
> test1/media, with a helpful information file in the media directory.
> All I had to do was delete the media directory that aspen created and
> replace it with a symbolic link to the directory in my django app
> structure, in this case it was located here:
>
> djangotest/test1/media
>
> That got item 1 from the list above working.
Perfect: that's exactly what I'd recommend.
> Now, to get item 2 working, I had to make a small edit to the
> grapelli.py file, as follows:
>
> Add this import at the top:
>
> from django.core.servers.basehttp import AdminMediaHandler
>
> And update this line at the bottom:
>
> django = AdminMediaHandler(WSGIHandler())
>
> That brought the admin site online.
It looks like AdminMediaHandler is just a WSGI middleware, no? In
that case, try adding this to __/etc/middleware.conf:
django.core.servers.basehttp:AdminMediaHandler
(Not working here: I'm guessing there is additional wiring in
settings.py that needs to happen, eh?)
> Item 3 - the dynamic PDF generation is not quite working yet.
Ok, this one looks much more Django-specific. I'll have to dig
into this later. :(
> 1. I would add an option in the apps.conf file that would let the user
See above. If we can make this work as middleware, that'd be my
preference. If it takes another shim, let's just add that to
grappelli.py, so __/etc/middleware.conf would look like:
grappelli:admin
> 2. I would add an option for serving static media that would let you
> map the URL for the location of the static media to a different place
> in the file system. But that is not a critical issue by any means. It
> may be better just to keep it the way that it is right now.
Yeah, as mentioned this is the way I would recommend. It's also
theoretically possible to use Django's own static handler, but
Aspen's is actually intended for production (although there's
certainly room for optimization ;) ).
> Chad thanks for all you work on this. I'm going to do some
> benchmarking now! :-)
Thanks again for your feedback! Let us know what your benchmarks
show. :)
chad
> that case, try adding this to __/etc/middleware.conf:
>
> django.core.servers.basehttp:AdminMediaHandler
>
> (Not working here: I'm guessing there is additional wiring in
> settings.py that needs to happen, eh?)
Thanks very much for the great suggestion!
Would it be helpful to you at all to have a copy of this small test
project that I put together yesterday? It's very self-contained
because it's using a sqlite database.
In this case I'm testing on an Ubuntu linux box using the following:
Python 2.4.3 (the standard version with Ubuntu)
In addition I have installed the following packages via apt-get:
sqlite3
python-pysqlite2
Then I have the following:
Your latest version of aspen and stephane
The latest version of django from here:
http://code.djangoproject.com/svn/django/trunk
The latest version of reportlab from here:
http://www.reportlab.co.uk/svn/public/reportlab/trunk
For the last two, I don't actually run the setup.py to install them. I
just create a symbolic link in /usr/lib/python2.4/site-packages. For
example, here are my links:
django -> /home/gordy/projects/python/django/trunk/django
reportlab -> /home/gordy/projects/python/reportlab/trunk/reportlab
--gordy
> Chad this totally worked:
Sweet!
> Would it be helpful to you at all to have a copy of this small test
> project that I put together yesterday? It's very self-contained
> because it's using a sqlite database.
Yeah, let's try that. Why don't add the PDF issue to the tracker:
http://code.google.com/p/aspen/issues/list
And upload your project as an attachment. We can winnow down from
there to pinpoint the bug.
Thanks again Gordy!
chad
OK, issue 88 has been posted along with the sample project. Hopefully
everything you will need to reproduce the test is documented in the
README.txt file.
Thanks so much for your help!
--gordon
P.S. - I don't know why but I have tried twice now to create a new post
to this group with the benchmarks results, but they just aren't showing
up... :-(
> OK, issue 88 has been posted along with the sample project. Hopefully
> everything you will need to reproduce the test is documented in the
> README.txt file.
Thanks! I'll check it out.
> P.S. - I don't know why but I have tried twice now to create a new post
> to this group with the benchmarks results, but they just aren't showing
> up... :-(
Hrm ... were they attachments? Google Groups might not allow that.
chad
--gordy
> Nope, just a plain old post. I think you should have a copy of it
> because I went ahead and used the google groups option to send an email
> to the owner of this group when I couldn't get the posts to show up.
Ah, ok. That'll be in my gmail box, which I only use for an
archive. Thanks for the heads-up. :)
chad
I could see that the inclusion of line
"django.core.servers.basehttp:AdminMediaHandler" in the __/etc/
middleware.conf solved the problem that did not allow Django to locate
their admin objects such as .css files. Actually it is working fine
and I can see the nice colors and fonts of Django in the "admin"
forms. thanks for that!!!
Then, I am not sure if the other problem about serving static files
was solved; may be I missed something in this thread. Let me dare to
insist in this topic. I made many attempts to to get this work but
without results. I beg your pardon if I include the next indications
related to apache/mod-python but actually, this schema is working for
me and I would like to know if there is a way to represent this in
aspen/stephane:
In Apache I have:
=============
Listen 8000
LoadModule python_module modules/mod_python.so
AddHandler mod_python .psp .psp_
AddHandler python-program .py
PythonHandler mod_python.psp
<VirtualHost *>
ServerName localhost
SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonPath "['C:/os/appLIT'] + sys.path + ['C:/python25/lib/site-
packages/django']"
SetEnv DJANGO_SETTINGS_MODULE elixir.settings
# Next line:
Alias /media c:\os\django\django_src\django\contrib\admin\media
# seems to be equivalent to middleware.conf line:
#django.core.servers.basehttp:AdminMediaHandler
Alias /attached c:\os\appLIT\elixir\media
<Location "/media">
SetHandler None
allow from all
</Location>
<Location "/attached">
SetHandler None
allow from all
</Location>
</VirtualHost>
In Django Settings.py I have:
====================
MEDIA_URL = 'http://localhost:8000/attached/'
In the models.py file of my django project I define the next field:
doc_attch = models.FileField(upload_to='recipies/%Y',
verbose_name='Document file', help_text='Document to attach')
Observe that I can include two additional structures in the uploaded
file name: recipies/year of the recipies so, when looking at my
document in the browser, the URL path indicates:
http://localhost:8000/attached/recipies/2006/german-cake-recipies.pdf
So, the file german-cake-recipies.pdf is located into next directory:
c:\os\appLIT\elixir\media\attached\2006\
Under this scenario I do not really know what to put in the apps.conf
file, I followed indications given in this thread without success.
Please let me ask for; according to settings I have in Apache and
Django, how would you configure apps.conf?
Thank you again for your attention.
Vizcayno.
Thanks for following up on this.
> I could see that the inclusion of line
> "django.core.servers.basehttp:AdminMediaHandler" in the __/etc/
> middleware.conf solved the problem that did not allow Django to locate
> their admin objects such as .css files. Actually it is working fine
> and I can see the nice colors and fonts of Django in the "admin"
> forms. thanks for that!!!
Excellent! Thanks for confirming. :)
> Then, I am not sure if the other problem about serving static files
> was solved; may be I missed something in this thread. Let me dare to
> insist in this topic. I made many attempts to to get this work but
> without results. I beg your pardon if I include the next indications
> related to apache/mod-python but actually, this schema is working for
> me and I would like to know if there is a way to represent this in
> aspen/stephane:
<snip>
> Under this scenario I do not really know what to put in the apps.conf
> file, I followed indications given in this thread without success.
> Please let me ask for; according to settings I have in Apache and
> Django, how would you configure apps.conf?
If I read you correctly, then your filesystem layout looks like this:
c:\os\appLIT\__\ <= Stephane
c:\os\appLIT\elixir\ <= your Django project
c:\os\appLIT\elixir\media <= static files
Try the following line in apps.conf:
/elixir/media aspen.apps:static
All requests for http://localhost:8080/elixir/media will no
longer be handled through Django, they will be served statically.
On Unix you could symlink this into your root directory to serve
the files at /attached (or whatever). Is there a way to do that
on Windows?
Does that give you enough to go on? If not please let me know!
chad
> c:\os\appLIT\__\ <= Stephane
> c:\os\appLIT\elixir\ <= your Django project
It is ok.
> c:\os\appLIT\elixir\media <= static files
It is true in part, my static files are really into c:\os\appLIT\elixir
\media\recipies\yyyy\ where yyyy=4 digits year.
the part of \recipies\yyyy\ is handled in my django model.py as I
explained in my previoues message, i.e.: doc_attch =
models.FileField(upload_to='recipies/%Y', verbose_name='Document
file', help_text='Document to attach')
> Try the following line in apps.conf:
> /elixir/media aspen.apps:static
I got errors because aspen.apps could not be found
I tried with:
/elixir/media aspen.handlers.static:static
and got next error when showing the browser window:
Traceback (most recent call last): File "c:\os\aspen\src\aspen
\wsgiserver.py", line 579, in communicate req.respond() File "c:\os
\aspen\src\aspen\wsgiserver.py", line 345, in respond response =
self.wsgi_app(self.environ, self.start_response) File "C:\os\django
\django_src\django\core\servers\basehttp.py", line 614, in __call__
return self.application(environ, start_response) File "c:\os\aspen\src
\aspen\website.py", line 48, in __call__ response = app(environ,
start_response) # WSGI File "c:\os\aspen\src\aspen\handlers
\static.py", line 23, in static assert
isfile(environ['PATH_TRANSLATED']) # sanity check AssertionError
Before the assert I put a print keyword showing
environ['PATH_TRANSLATED'] and the result was: C:\os\appLIT\elixir
\media
however in thed URL of the browser it shows:
http://localhost:8000/elixir/media/recipies/2006/german-cake-
recipies.pdf
I forced apps.conf to:
/elixir/media/recipies/2006/ aspen.handlers.static:static
and issued the previous error too, in this case
environ['PATH_TRANSLATED'] was with: c:\os\appLIT\elixir\media
\recipies\2006
> All requests forhttp://localhost:8080/elixir/media will no
> longer be handled through Django, they will be served statically.
Well, instead of using symlink I changed settings.py from:
MEDIA_URL = 'http://localhost:8000/attached/' to MEDIA_URL = 'http://
localhost:8000/elixir/media/'
> On Unix you could symlink this into your root directory to serve
> the files at /attached (or whatever). Is there a way to do that
> on Windows?
>
Windows uses junction.exe. I got it from:
http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?
page=EncryptedFileSystem
but was not necessary to use, unless yes??
Thanks your help and patience.
Regards.
>> c:\os\appLIT\elixir\media <= static files
> It is true in part, my static files are really into c:\os\appLIT\elixir
> \media\recipies\yyyy\ where yyyy=4 digits year.
Ok, per my previously suggested setup, any subdirectories of
elixer\media will also be served statically, so this should be ok.
>> Try the following line in apps.conf:
>> /elixir/media aspen.apps:static
> I got errors because aspen.apps could not be found
Are you sure you're at version 150 of the Aspen trunk? I find
this there:
http://aspen.googlecode.com/svn/trunk/src/aspen/apps/static.py
Do you have that file locally?
> I tried with:
> /elixir/media aspen.handlers.static:static
>
> and got next error when showing the browser window:
Right, that's why we added the aspen:apps:static application.
Let's try to get that working for you.
chad
> Ok, per my previously suggested setup, any subdirectories of
> elixir\media will also be served statically, so this should be ok.
>
You are right, it worked without problems.
> >> Try the following line in apps.conf:
> >> /elixir/media aspen.apps:static
> > I got errors because aspen.apps could not be found
>
> Are you sure you're at version 150 of the Aspen trunk? I find
> this there:
I did not obtain the last version of /trunk, that was my fault, but I
rectified this; even, it was necessary to change from:
/elixir/media aspen.apps:static
to
/elixir/media aspen.apps.static:static
In that way, it worked nicely.
I made some tests in my local site. I used Win XP and IE7. I have some
feedbaks for you and, sorry if I did not explore your code to help
more.
1) When trying to read static text files (small or big files) it is
very fast. Entire data is displayed inmediately however, the "progress
indicator" component at the botton of the IE7 continues moving in
wating status as if some data was pending to be displayed. (hope you
understood my explanation)
2) I have problems when trying to read .pdf, .doc and .xls files, it
is very slow to recover data and, at the end, the IE7 explorer usually
hangs when file is big or next errors shows for .pdf files: "There was
an error opening this document. The file is damaged and could not be
repaired"; then it shows the pdf window without data. For excel docs
shows next error: "File with not recognized format" then I can see the
excel window with row and column one showing unrecognized characters.
That was all by the moment Chad, hope it can help you. If you need
some clarifications, please let me know.
In general, I can see that the architecture of your product is very
elegant and promising and I appreciate your efforts and ... kindness.
Actually I can switch between your product and Apache without changing
code or configurations so, I will be pending about your new surprises.
Very best regards!!!!
> 2) I have problems when trying to read .pdf, .doc and .xls files, it
> is very slow to recover data and, at the end, the IE7 explorer usually
> hangs when file is big or next errors shows for .pdf files: "There was
> an error opening this document. The file is damaged and could not be
> repaired"; then it shows the pdf window without data. For excel docs
> shows next error: "File with not recognized format" then I can see the
> excel window with row and column one showing unrecognized characters.
I have recently added some modified utils.py and handlers/static.py to
branches/iGL-cached/src/aspen/extra/
Would you take a look? You could get them, overwrite the trunk/src/
aspen/utils.py and trunk/src/aspen/handlers/static.py, run then
`python setup.py develop` and test the performance.
The new utils.py introduces StaticResource iterable, which emulates
file streaming. It's modelled after venerable quixote's
util.FileStreame, but is somehow modified. What it does is that it
reads chunks and yields them, thus it fits the wsgi protocol.
The configuration options are as follow: put in the main aspen.conf :
[statics]
chunk_size = whatever or 0 to turn off
If this section is omitted, or chunk_size is set to 0, aspen will
simply open the file end return, just like aspen of rev 150 does.
Otherwise, the file is wrapped into Static Resource and served only
afterwards.
My tests: when I make aspen serve large pdfs with chunk-size set to 0,
I get just the same error as you do ("There was an error opening this
document. The file is damaged and could not be repaired"); if,
however, I use StaticResource, everything is ok, aspen delivers the
content of appr. 15 mB pretty fast, without errors.
Any feedback is appreciated. If your and other users' tests show the
same as mine, this part of the branch will probably be merged into the
trunk.
greetings,
giorgi
P.S. I shall modifiy the behavoir a little: if chunk_size > 0 but the
size of the file in question is small than chunk_size, StaticResource
will not be called anyway.
.python aspen -a0.0.0.0:8000
Traceback (most recent call last):
File "aspen", line 3, in <module>
aspen.main()
File "c:\os\aspen\src\aspen\__init__.py", line 246, in main
start_server(config)
File "c:\os\aspen\src\aspen\__init__.py", line 78, in start_server
config.load_plugins()
File "c:\os\aspen\src\aspen\config.py", line 317, in load_plugins
self.apps = self.load_apps()
File "c:\os\aspen\src\aspen\load.py", line 267, in load_apps
obj = colon.colonize(name, fp.name, lineno)
File "c:\os\aspen\src\aspen\colon.py", line 38, in colonize
exec 'import %s as obj' % modname
File "<string>", line 1, in <module>
File "C:\os\appLIT\__\lib\python2.x\grappelli.py", line 15, in
<module>
sys.path.insert(0, aspen.paths.root)
AttributeError: 'module' object has no attribute 'paths'
Thanks for your interest.
Very best regards.
greetings,
giorgi
greetings
giorgi
P.S. don't forget to keep chunk_size reasonably smaller than file
size ;-)
> Hi,
> I've created another branch on svn: iGL-statres; now you can checkout
> this branch and test against large static content service.
Thanks!! Do I download entire one?
> Installation is again via `python setup.py develop`.
Is this really necessary to execute the previous command? Currently I
have Aspen in a directory outside's python ones and never executed
setup.py.
> greetings
> giorgi
>
> P.S. don't forget to keep chunk_size reasonably smaller than file
> size ;-)
Ok, thanks for your recommendation.
> Is this really necessary to execute the previous command? Currently I
> have Aspen in a directory outside's python ones and never executed
> setup.py.
When you run setup.py develop, only symlink to the egg is put in the
easy-install.pth ; any change in the source files is immediatly
available. That's it. If you rely on some custom installation
locations, then, running the command might be redundant.
greetings
giorgi
> Hello Giorgi:
> The solution you proposed under branch iGL-statres is now working as
> expected. I can now read static files without problems.
> About performace, I can read a 20MB .pdf files in 3 seconds the first
> time I make click on the link to the static file, 2 seconds when I re-
> read the file (a new click on the link), 3 seconds the third time, 2
> seconds the fourth ....
> Apache does it in 2 seconds in an uniform way.
I guess I have to re-examine 'close' and '__init__' functions of
'StaticResource'... Could there be anything else?..
> The value I put in chunk_size was 8192 but when I put 100 I did not
> perceive differences. Incidentally, which is the recommended value? is
> there a formula to obtain an optimal value?
I myself mostly use 8192 or 4096 - just empyrically. I really don't
know about any theory upon.
> Giorgi, I think you made a nice work, it looks very stable.
> Many thanks and best regards!!! I will stay tuned.
> Vizcayno.
Thanks a lot again ;)
> 1) ... however, the "progress indicator" component ...
> 2) I have problems when trying to read .pdf, .doc and .xls files
I was able to reproduce the second of these, and have confirmed
that Giorgi's fix works. I am therefore incorporating that on the
trunk.
Thanks Vizcayno for the report and Giorgi for the fix!
chad
meanwhile I slightly modified iGL-statres/src/aspen/apps/static.py:
http://aspen.googlecode.com/svn/branches/iGL-statres/src/aspen/apps/static.py
Now it can serve any dir outside aspen, just give doc_root = /abs/path/
to/the/dir in the [statics] section.
Hopefully, it also simplifies serving django apps' media.
Feedbacks are gratefully aknowledged ;)
giorgi
I made some tests and it is working nice at the moment. You will not
believe me but I needed something like that. I have my Django project
(it is in swaddling clothes yet) and was asking, how can I isolate the
data (databases, static files) from my application structure? For
example I have:
os
dev
mix
media
templates
app1
app2
And I wanted:
os
dev
mix
templates
app1
app2
media
dev
mix
So, with your soIution I configured in the next way:
settings.py of Django:
===============
changed from:
#MEDIA_URL = 'http://localhost:8000/mix/media/'
to:
MEDIA_URL = 'http://localhost:8000/os/media/dev/mix/'
Note. MEDIA_ROOT seems not to have sense (although who knows),
actually I don't use it.
aspen.conf
========
[django]
settings_module = mix.settings
[statics]
chunk_size = 8192
doc_root = c:/os/media/dev/mix # added according to your
indications
apps.conf
========
/ grappelli:django # see __/lib/python2.x/grappelli.py
/mix/media aspen.apps.static:static # before your change I used
it
/os/media/dev/mix aspen.apps.static:static
As a reference only, in Apache 2, the solution is typing the next
line:
Alias /os/media/dev/mix c:\os\media\dev\mix
At this moment I can run both Aspen and Apache simultaneously (in
different ports) without changing Django configuration (although port
8000 is used by Aspen and Apache for static files).
Thanks and very best regards Giorgi!!
Vizcayno.
Aspen creates a directory for any app listed in __/etc/apps.conf.
With Giorgi's doc_root patch you don't need any extra config in
apps.conf. Clear that out and remove the directory: it shouldn't
be recreated.
chad
> Aspen creates a directory for any app listed in __/etc/apps.conf.
> With Giorgi's doc_root patch you don't need any extra config in
> apps.conf. Clear that out and remove the directory: it shouldn't
> be recreated.
Er, that's not entirely accurate. But the reason Aspen is
creating the directory is the aspen.conf listing. See:
http://www.zetadev.com/software/aspen/latest/doc/html/apps.html
chad
> meanwhile I slightly modified iGL-statres/src/aspen/apps/static.py:
>
> http://aspen.googlecode.com/svn/branches/iGL-statres/src/aspen/apps/static.py
>
> Now it can serve any dir outside aspen, just give doc_root = /abs/path/
> to/the/dir in the [statics] section.
> Hopefully, it also simplifies serving django apps' media.
Interesting move. :^)
As you know Aspen is designed to use the filesystem for site
hierarchy. What we are hitting here is the desire to use Aspen's
static serving capabilities outside of such a hierarchy.
Another way to layer this in w/o changing Aspen directly would be
with a wrapper like this (such is the power of WSGI):
------------------------------------
from aspen import conf
from aspen.apps.static import static
def other_static(environ, start_response):
"""Wrapper for static to use an arbitrary directory as root.
"""
root = environ['PATH_TRANSLATED']
root = conf.statics.get('doc_root', root)
environ['PATH_TRANSLATED'] = root
return static(environ, start_response)
------------------------------------
I may need to rethink the filesystem-as-hierarchy design choice,
but until then I'd like to keep tricks like this out of the Aspen
core. They are *most* welcome in your own bag of tricks, however,
as Aspen/WSGI encourage such flexibility.
chad
> asker wrote:
> apps.conf
> ========
> / grappelli:django # see __/lib/python2.x/grappelli.py
> /mix/media aspen.apps.static:static # before your change I used
> it
> /os/media/dev/mix aspen.apps.static:static
I think you could leave the previous setting - it should serve the
same actual dir, given via doc_root. It's like apache's aliasing, as
you mention below. On another hand, the path given as alias, as far as
I remember django, must be similar to the one given in templates
( say, in base.html: <link rel="stylesheet" type="text/css" href="/mix/
media/mystyle.css" /> ); e.g., in urls.py, one gives (r'^mix/media/(?
P<path>.*)$', 'media', {'document_root': '/path/to/actual/media/dir'})
when using the django's built-in wsgi server.
I am sorry but I haven't tested these recommendations, - hope it
would be of some interest to you anyhow :)
greetings,
giorgi
Actually I am using Aspen with your nice effort in an equipment that
does not allow me to have Apache; and, by the moment, I am not having
troubles.
Thanks!!!