简体   繁体   中英

static html page in Django

I'm building a fairly simple experiment to run as a website.
It's all javascript, so all I need the server for is to store the experiment results. I've set up a Django server on WebFaction, but my problem is making django redirect clients to the 1st static html page (from where js takes over).

I gather my solution should be something like this (using django 1.7.1):

urls.py

django.views.generic import RedirectView  

urlpatterns = patterns('',
    url(r'^$', RedirectView.as_view (url='fudge.html'))
)

It works when DEBUG = True on settings.py , but when it's set to False I get:

Not Found
The requested URL /fudge.html was not found on this server.

Iv'e set STATIC_ROOT = '/AmirStatic/' in settings.py and ran python manage.py collectstatic following instructions iv'e found on the net, but this didn't do the Trick. Either I don't understand the path settings in Django or they are not configured properly or I don't understand how static webpages are used. But I would have thought it would be much simpler than this. Iv'e spent a good 3 days losing hair over it.

I would be very thankful to anyone with good advice on this,
thanks a lot in advance.

Oh and i'm a newbie to python, Django and web-developing in general if that hasn't come across :)

When you are developing, Django can serve your statics files, but when going into production, django doesn't serve your static files (and should not, it should be handled by your reverse proxy such as nginx or apache)

Please take a look at the Deploying static files of the django documentation.

As @Mihai Zamfir suggested above-- try actually using a URL and linking to a view. Then within the view you define the logic for the template which is contained in fudge.html .

Example:

url(r'^fudge/$', views.fudge_view, name='fudge')

This is assuming you also have in your urls.py :

from your_app_name import views 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM