#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0

    Python, django, nginx, fastcg i- How they work together and index.fcgi ?


    Hi,
    I have 2 questions and I would be most grateful for some help please.

    I am having great problems with understanding how nginx loads up a django application using fastcgi.
    I have a development server running nginx and fastcgi on a Debian squeeze system.

    In my django project directory, there is an index.fcgi which I want to be loaded when I go to the local domain http://mydomain.lcl
    I guess that the index.fcgi is a python program which gets loaded and interpreted by the fastcgi server which gets called by the nginx location block to handle the index.fcgi.

    I assume there is some mechanism to get from the index.fcgi to the django application directory and on from there to running the application.

    My first question is...
    Where can I read up about this process please?

    My second question is...
    What can I place in the index.fcgi to basically display "Hello World" or "this is index.fcgi" so that I know everything is being routed correctly through nginx, fastcgi, and reaching the django project directory?

    something like this, but this does not do it.
    =========================
    index.fcgi

    Code:
    #!/usr/bin/python
    # 
    # djangoblog/index.fcgi
    from django.http import HttpResponse
    
    HttpResponse("Hello, world. You're at the djangoblog index.fcgi")
    =========================

    This is all part of a larger problem, but if I can understand how to do this, then I may be able to get to the bottom of the larger problem and learn a bit on the way.

    Thanks,
    Paul
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0
    Ok, so this is partially solved and may help others who want to just display a page to help them track down errors.

    When I did not have the Content-Type: statement at the top (as the first output statement), I got a 502 bad gateway error in nginx.

    Code:
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    
    print "Content-Type: text/html"
    print "<html><head><title>my title</title><head>"
    print "<body><p><b>This</b> is the body of the page</p></body></html>"
    This should render correctly if you point your fastcgi server at it, and should show the "This" word in bold.

    Hope that helps.
    Paul
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Thanks for the update. I bypassed your question because I'd never heard of 2 of
    python, django, nginx, fastcg
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0
    I also found out that you have to have an extra 'print' statement after the Content-Type: line or else place a newline at the end of that string. Otherwise the browser page is blank.
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    Can someone presnt a simple hello world that utilizes Django so i cam understand how this web framework looks like?

    i heard it is complicated to write code with django.
    What is now proved was once only imagined!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0
    Nik, as I understand it at the moment, if you take the code in the OP and stick it into a def statement in views.py then you will see this in your browser. However, you have to have an entry in urls.py to make it go there. See the tutorial which is very good if you need more info.
  12. #7
  13. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    Hello,

    whre is the link for tutorial plz?
    What is now proved was once only imagined!
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0
    Originally Posted by Nik
    Hello,whre is the link for tutorial plz?
    Oh come on Nik. The Django Tutorial. Put a bit of effort into this. Google it. :-) You will never learn anything unless you are motivated to do so. That means effort because you want to do it and it is interesting.

IMN logo majestic logo threadwatch logo seochat tools logo