I have a simple subroutine written in Fortran. Just for testing reasons it is as simple as this:
!test.f90
subroutine test()
end subroutine test
It compiles well with gfortran and with f2py. I compile it with f2py like so:
$ f2py -m test -c test.f90
If I go to python, I can import it and everything works ok:
>>> import test
>>> test.test() # ok. nothing as expected and with no errors
In django I have an app called just myapp. It has a view which looks like this:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from numpy import *
from test import * # the module itself imports ok, I get no errors
def index(request):
template = loader.get_template('myapp/index.html')
#test.test() # but if I try to call a function from it, I get an error
context = RequestContext(request,{})
return HttpResponse(template.render(context))
The error message is: AttrubuteError at /myapp/ test. PS. I'm a python and django newbee, so I guess I could make some "stupid" error.
EDIT
Now, thanks to laike9m, I manage to call a fortran function, at least I do not have error any longer. But at the same time it seems as if the function does nothing. I mean this. I changed my fortran function a little bit, so that it now writes some stuff to a file. If I check it in pure python, I see that it works - a file is modified. But if I call it in django, it does not modify it. So, my codes now look like this:
!fortran code
!test.f90
subroutine test()
open(1,file='test.txt',status='replace')
write(1,*) "Hello, Django! My name is Fortran."
close(1)
end subroutine test
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from numpy import *
from test import * # it's ok
def index(request):
template = loader.get_template('myapp/index.html')
test() # no error any longer, but the function itself does nothing
context = RequestContext(request,{})
return HttpResponse(template.render(context))
So, my question is how to check whether fortran module works or not?
EDIT
Thanks to laike9m and Vladimir, I finally did it. The problem was in the path to the file. I had to put the file right in the root folder of the project.
1or anything smaller than 11. They can have a special purpose and be pre-connected.