简体   繁体   中英

writing a file from django view to static folder (django running via apache 2.2): [Errno 2] No such file or directory:

  1. Creating some data in Django which i write in static file directory
  2. Calling same file later from jquery and showing data on chart

This process works good when i run my project from django development server . Below is how i am calculating the path for the json file :

def ExpenditureTypesPieChartJson(P_USER):
    chartFilename='money/static/money/data/highchartpie'+P_USER+'.json'
if textPieChartPerExpenditureTypeJSON is not None:
        f = open(chartFilename, 'w+')
        f.write(textPieChartPerExpenditureTypeJSON)
        f.close()

and when i use this , it created a file in following directory :

C:\wsgi_app\tango_with_django_project\money\static\money\data

in settings.py i have set static path as following

STATIC_ROOT = 'C:/wsgi_app/tango_with_django_project/tango_with_django_project/money/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "money/static"),
)

doing all above steps works fine . However I just moved my project to run from apache server . project is reading the bootstrap files and other static files properly however when it tries to write the data for the json as mentioned above it gives error

IOError at /money/

[Errno 2] No such file or directory: 'money/static/money/data/highchartpiepa.json'

Below are the settings i am using the configure the apache :

httpd.conf

Include     C:/wsgi_app/tango_with_django_project/tango_with_django_project/apache/apache_django_wsgi.conf

apache)django_wsgi.conf

WSGIScriptAlias / C:/wsgi_app/tango_with_django_project/tango_with_django_project/apache/tango_with_django_project.wsgi

<Directory C:/wsgi_app/tango_with_django_project/tango_with_django_project/apache>
Allow from all
</Directory>


Alias /static/ C:/wsgi_app/tango_with_django_project/money/static/

<Directory C:/wsgi_app/tango_with_django_project/money/static/>
Order allow,deny
Allow from all
</Directory>

I am using same code to write file in static folder as i was doing in django development server , but could not understand why its not above to find the path via apache server , it is reading all css and js files correctly .

Can anyone advice something ?

The problem is that you are using a relative path name. The working directory of your wsgi application (/) doesn't have your directories. You could hard code the full path name, create a configuration file for your application that you read to get the path or even have wsgi set the current directory for you (see mod_wsgi working directory and user

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