0

I browsed these question but not found correct answer. Here is my problem..

I have some static files.Here is the dir..

/home/user/djangoproject/djangoapp/static

/home/user/djangoproject/templates/base.html (where I have modify some for django admin page)

After setting debug = False, I have change setting.py like this

DEBUG = False
ALLOWED_HOSTS = ['*',]
STATIC_URL = '/static/'
STATIC_ROOT = "/home/user/djangoproject/djangoapp/static/"

and my urls.py is

urlpatterns = patterns('',
                 url(r'^admin/', include(admin.site.urls)),
                 url(r'^$',login),# and some more views
    )+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

After that I have collect all admin static to my app's custom static dir path like this..

/home/user/djangoproject/djangoapp/static/admin/css & all others

Now my problem is that when I am using my custom static file, It's working but for example admin login page & admin site, admin static file is not working..So where am I doing wrong, or what extra I have to do.

Thanks in advance...

Swagat
  • 617
  • 5
  • 16
  • have you run the `collectstatic` command? – yedpodtrzitko Jan 15 '14 at 14:20
  • yes,By that only I got copy all admin static files – Swagat Jan 15 '14 at 14:21
  • Do you mean, that the admin static files show properly, if debug is True? – skoll Jan 15 '14 at 14:24
  • well afaik the function `static` doesnt work with `DEBUG` set to `False` (check its source code) because of security or something. You've to create an alias in your webserver for the directory containing all your static files, see https://docs.djangoproject.com/en/1.4/howto/static-files/#serving-static-files-in-production – yedpodtrzitko Jan 15 '14 at 14:25
  • Yes, Getting no problem with DEBUG True – Swagat Jan 15 '14 at 14:26
  • @yedpodtrzitko sorry I did not get it "You've to create an alias in your webserver for the directory containing all your static files". Do you min /var/www/static ... if Yes,I want to tell you that, In production I am only using djano + python(python manage.py runserver).. So how can I able to get it , please explain briefly. – Swagat Jan 15 '14 at 14:33
  • @Swagat it's not recommended to run Django projects using `runserver`in production. – skoll Jan 15 '14 at 14:37
  • 2
    Did you miss the bold and extremely prominent warning throughout the docs on how runserver is unsafe and should **never** be used in production? – Daniel Roseman Jan 15 '14 at 14:37
  • @ skoll this is my first web project & no one have to guide me.. So I run like this only.. Please suggest me what to do as I have low idea about appache. It will be great if you tell me how to deploy as I don't get understand in documents – Swagat Jan 15 '14 at 14:41
  • @DanielRoseman Can please come to chat... http://chat.stackoverflow.com/rooms/45379/discussion-between-swagat-and-skoll?highlights=false – Swagat Jan 17 '14 at 07:48

1 Answers1

1

You need to set up a web server to serve the static files. If you are using Apache, adding something along the lines of

Alias /static/ /home/user/djangoproject/djangoapp/static/
<Directory /home/user/djangoproject/djangoapp/static>
        Order deny,allow
        Allow from all
</Directory>

to httpd.conf should do the trick. For more info see https://docs.djangoproject.com/en/1.6/howto/static-files/deployment/

To serve also the Django project through Apache, add

WSGIScriptAlias / /home/user/djangoproject/djangoproject/wsgi.py
WSGIPythonPath /home/user/djangoproject

<Directory /home/user/djangoproject/djangoproject>
  <Files wsgi.py>
    Order deny,allow
    Allow from all
  </Files>
</Directory>

Alias /static/ /home/user/djangoproject/djangoapp/static/
<Directory /home/user/djangoproject/djangoapp/static>
  Order deny,allow
  Allow from all
</Directory>

to httpd.conf. For instructions about how to set up Django with Apache, see https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/

skoll
  • 2,272
  • 4
  • 30
  • 33
  • Thank you for answer. Can you please see my question's last comment..Sorry for saying like this – Swagat Jan 15 '14 at 14:36
  • @Swagat See my update. How to install Apache, you need to figure out yourself, as it depends on your OS (it's really not difficult). Next you need to set up mod_wsgi (https://code.google.com/p/modwsgi/). After that configure Apache as instructed in my answer. – skoll Jan 15 '14 at 15:19
  • I got a problem. My httpd.conf file is empty & SERVER_CONFIG_FILE is running apache2.conf showing in terminal..So am I have to copy all line of apache2.conf to httpd.conf..(apache2.conf is located at /etc/apache2 – Swagat Jan 16 '14 at 13:41
  • What OS are you running on? Anyways, it should be enough to just copy the configuration to httpd.conf. It doesn't matter, that it's currently empty. – skoll Jan 16 '14 at 13:46
  • I am using ubuntu 12.04 LTS & in apache2.conf one line is written (# Include all the user configurations: Include httpd.conf) and ServerRoot "/etc/apache2" line is in comment. should I uncomment it. – Swagat Jan 16 '14 at 13:52
  • `Include httpd.conf` should be uncommented. – skoll Jan 16 '14 at 13:55
  • BTW, don't forget to restart Apache after the changes: `/etc/init.d/apache2 restart` – skoll Jan 16 '14 at 13:56
  • I got SERVER_CONFIG_FILE by running this command 'ps -ef | grep apache' & after that '/usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE'.. The o/p is '-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"'.. So I am afraid, If i will copy, It may couse a bug. – Swagat Jan 16 '14 at 13:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45379/discussion-between-swagat-and-skoll) – Swagat Jan 16 '14 at 13:57
  • SQLite3 Database locked error Sol'n = http://serverfault.com/questions/57596/why-do-i-get-sqlite-error-unable-to-open-database-file – Swagat Jun 30 '14 at 12:04