python - import problem with twisted.web server -


I'm just starting with twisted.web, and I have a problem importing a Python module in a Script .rpy script. In

C: \ py \ twisted \ mysite.py , I have this:

twisted .web.resource imported from twisted. Web import server class resource from MySite (resource): def render_GET (auto, request): request.write ("& quot; DOCTYPE html & gt;") request.write ("& lt; html & gt; & lt; (& Lt; body & gt;) Request.; / H1> ") request.write ("

Prepath: {0} ") request.finish () Return Server .NOT_DONE_YET < / Code>

and c: \ py \ twisted \ index.rpy I have it:

  import mysit e reload ( Mysite) resources = mysite.mysite ()  

I ran twistd -n web --port 8888 --path c: \ py \ twisted command prompt and the server started successfully but when i localhost: 8888 , then I found a huge (huge) stack trace generated from an imported errter:

I can import modules from the interpreter, and if I just select index.rpy If I execute as a dragon script, then I do not get an import error. The documentation on this topic is a bit unclear, it just says "However, it is often a better idea to define resource subclasses in Python module. To be visible for changes in the module, you must either restart the Python process Must be reloaded, or module: "(from).

Does anyone know the proper way to do this?

short answer: to include you c: \ py \ twisted There is a need to set the pathstone.

Long answer ...

One such script is basically just some python code, like any other python code. Therefore, any import in one rupee script works like importing into another python code for the most common case, it means that the directories present in sys.path are viewed one by one, and If any .py file matches the imported name, that file is used to define the module.

sys.path is mostly populated with a static definition in which C: \ Python 26 \ lib \ and pithonpath environment variables, however, learn about it There is an additional thing to do when you run "Python", then the existing working directory is added to sys.path . When you run "Pyro c: \ fu \ bar \ baz.py", then c: \ foo \ bar \ 'is added to sys.path . But when you run "twisted ...", then sys.path`

< / P>

If you run python and interactively try to import the module, but fails when you use twistd C: The modules should be importable by adding \ py \ twisted to PYTHONPATH , when the rpy script runs from the server that you start with twistd.


Comments