I want advice on how to do the following:
On the same server, I want to have two apps. One WordPress app and one Python app. At the same time, I want the root of my domain to be a static landing page.
Url structure I want to achieve:
example.com/ => static landing page
example.com/tickets => wordpress
example.com/pythonapp => python app
I have never done something like this before and searching for solutions didn't help.
Is it even possible?
Is it better to use subdomains?
Is it better to use different servers?
How should I approach this?
Thanks in advance!
Yes, it is possible with php rewrite engine.
Internally the wordpress app may have some random URL, but you can modify it and show as whatever you wanted it to the users.
once have a look at this
https://www.addedbytes.com/blog/url-rewriting-for-beginners
It depends on the webserver you want to use. Let's go with apache as it is one of the most used web servers on the internet.
You install your wordpress installation into the /tickets subdirectory and install word-press as you normally would. This should install wordpress into the subdirectory.
Configure your Python-WSGI App with this configuration:
WSGIScriptAlias /pythonapp /var/www/path/to/my/wsgi.py
Pardon me, this question is going to be too basic but i have not been able to get the solution anywhere. So, here goes ..
I have set up an instance nginx on Ubuntu 14.04 and an instance of uWSGI on port 9090.
I can direct the traffic from nginx to that one instance of uWSGI, and it works.
But every hello world example i see has something like this
> def application(env, start_response):
> start_response('200 OK', [('Content-Type','text/html')])
> return "Hello World From uWSGI"
and it is just one file... so, if i have multiple python files that needs to be served, distributed through a tree of subdirectories [basically my project]. How can I set that directory structure available for use through HTTP requests?
I would NOT like to use any frame work like Django of flask. But serve simple python file, similar to how a pure html site distributed through subdirectories would serve html.
i might also be missing some concept of how routing can be done. As i feel that has never come up till now.
The directory structure has logic that manipulates a database or interacts with thrid party apis.
Need some guidance to start off.
[Please let me know if there is totally a different way to archive what i am in need of, or if i am on the right track]
Thanks.
The application function is responsible for everything. Of you want to do routing, you do it there, by parsing the request path in env['PATH_INFO'] and then importing and calling the relevant Python functions.
But that would be rather a silly thing to do, seeing is that is exactly what Flask would do for you. You don't need to use anything else from the framework it you really don't want to.
I have implemented a very small application with Tornado, where HTTP GET Requests are used to perform actions. Now I would like to secure these requests. What would be a preferable way? Using .htaccess? How can I realize that?
It doesn't have to be for certain requests, it should be for all requests running on a certain port.
If you based your application on the Tornado "Hello World" example then you probably haven't, but you really should consider writing your application as a WSGI application. Tornado has no problem with that, and the advantage is that your application now will run under a multitude of other environments (Apache + mod_wsgi to name but one).
But how does that solve your original problem? Well, just Google "WSGI authentication middleware", it'll yield plenty of hits. Basically, what that entails is transparently 'wrapping' your WSGI-application in another, one allowing you to completely decouple that aspect of your application. If you're lucky, and one of hits turns out to be a perfect fit, you might get away with not witing any extra code at all.
Since you mentioned .htaccess: it is possible to have Apache do the authentication in an Apache/mod_wsgi configuration.
.htaccess files are not supported by Tornado as far as I know. Look into setting up basic authentication on Tornado. Something like this: https://gist.github.com/660185 is probably what you want. You'll need to store your own user credentials however as Tornado has no baked in support for that as apache does with .htaccess files.
I'm looking for a suitable cross-platform web framework (if that's the proper term). I need something that doesn't rely on knowing the server's address or the absolute path to the files. Ideally it would come with a (development) server and be widely supported.
I've already tried PHP, Django and web2py. Django had an admin panel, required too much information (like server's address or ip) and felt unpleasant to work with; PHP had chown and chmod conflicts with the server (the code couldn't access uploaded files or vice versa) and couldn't handle urls properly; web2py crashed upon compiling and the manual didn't cover that -- not to mention it required using the admin panel. Python is probably the way to go, but even the amount of different web frameworks and distributions for Python is too much for me to install and test individually.
What I need is a simple and effective cross-platform web development language that works pretty much anywhere. No useless admin panels, no fancy user interfaces, no databases (necessarily), no restrictions like users/access/levels and certainly no "Web 2.0" crap (for I hate that retronym). Just an all-powerful file and request parser.
I'm used to programming in C and other low level languages, so difficulty is not a problem.
This question is based on a complete failure to understand any of the tools you have apparently "investigated", or indeed web serving generally.
Django has an admin panel? Well, don't use it if you don't want to. There's no configuration that needs to be done there, it's for managing your data if you want.
PHP has chown problems? PHP is a language, not a framework. If you try and run something with it, you'll need to set permissions appropriately. This would be the case whatever language you use.
You want something that doesn't need to know its address or where its files are? What does that even mean? If you are setting up a webserver, it needs to know what address to respond to. Then it needs to know what code to run in response to a request. Without configuring somewhere the address and the path to the files, nothing can ever happen.
In web2py you do not need to use the admin interface. It is optional.
Here is how you create a simple app from zero:
wget http://web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
cd web2py/applications
mkdir myapp
cp -r ../welcome/* ./
Optional Edit your app
emacs controllers/default.py
emacs models/db.py
emacs views/default/index.html
...
(you can delete everything in there you do not need).
Now run web2py and try it out
cd ../..
python web2py.py -i 127.0.0.1 -p 8000 -a chooseapassword &
wget http://127.0.0.1:8000/myapp/default/index.html
When you edit controller/default.py you have a controller for example
def index():
the_input = request.vars # this is parsed from URL
return dict(a=3,b=5,c="hello")
You can return a dict (will be parsed by the view with same name as action) or a string (the actual page content). For example:
def index():
name = request.vars.name or 'anonymous'
return "hello "+name
and call
wget http://127.0.0.1:8000/myapp/default/index?name=Max
returns
'hello Max'
/myapp/default/index?name=Max calls the function index, of the controller default.py of the application in folder applications/myapp/ and passes name=Max into request.vars.name='Max'.
I think you need to be more specific about what you want to achieve, and what kind of product(s) you want to develop. A "no setup required" product may come with tons of auto-configuration bloat, while a framework requiring a small setup file could be set up in minutes, too, with much more simplicity in the long run. There is also always going to be some security and access rights to be taken into consideration, simply because the web is an open place.
Also, a framework supporting Web 2.0ish things doesn't have to be automatically a bad framework. Don't throw away good options because they also do things you don't like or need, as long as they allow you to work without them.
PHP had chown and chmod conflicts with the server (the code couldn't access uploaded files or vice versa) and couldn't handle urls properly;
PHP is not a framework in itself, it's a programming language. I don't know which PHP-based framework or product you tried but all the problems you describe are solvable, and not unique to PHP. If you like the language, maybe give it another shot. Related SO questions:
What PHP framework would you choose for a new application and why?
What’s your ‘no framework’ PHP framework?
If you need something that runs everywhere (i.e. on as many servers as possible) PHP will naturally have to be your first choice, simply because it beats every other platform in terms of cheap hosting availability.
If I were you, I wouldn't limit my options that much at this point, though. I hear a lot of good things about Django, for example. Also, the Google App engine is an interesting, scalable platform to do web work with, supporting a number of languages.
Werkzeug:
import werkzeug
#werkzeug.Request.application
def app(request):
return werkzeug.Response("Hello, World!")
werkzeug.run_simple("0.0.0.0", 4000, app)
You can optionally use werkzeug URL routing (or your own, or anything from any other framework). You can use any ORM or template engine for Python you want (including those from other Python frameworks) etc.
Basically it's just Request and Response objects built around WSGI plus some utilities. There are more similar libraries available in Python (for example webob or CherryPy).
What I need is a simple and effective cross-platform web development language that works pretty much anywhere.
Have you tried HTML?
But seriously, I think Pekka is right when he says you need to specify and clarify what you want.
Most of the features you don't want are standard modules of a web app (user and role mgmt., data binding, persistence, interfaces).
We use any or a mix of the following depending on customer requirements: perl, PHP, Flash, Moonlight, JSP, JavaScript, Java, (D/X)HTML, zk.
I am python newbie but experienced PHP developer for 12 years but I have to admit that I migrated to python because of the bottle framework. I am African so you don't have to be extra smart to use it... Give it a try, you'll love it. Hey and it also runs on appspot with no config!
Install python
Download bottle.py (single file)
Create
#your file name : index.py
from bottle import route, run
#route('/')
def index():
return 'jambo kenya! hakuna matata na bottle. hehehe'
run()
Sit back, sip cocoa and smile :)
I'd say Ruby on Rails is what you're looking for. Works anywhere, and no configuration needed. You only have it installed, install the gems you need, and off you go.
I also use ColdFusion, which is totally multi-platform, but relies on the Administrator settings for DSN configuration and stuff.
TurboGears: Everything optional.
Give bottle a try. I use it for my simple no-frills webapps. It is very intuitive and easy to work with in my experience.
Here is some sample code, and it requires just bottle.py, no other dependencies.
from bottle import route, run
#route('/')
def index():
return 'Hello World!'
run(host='localhost', port=8080)
Just stumbled upon Quixote recently. Never used it though.
Use plain old ASP. IIS does not care where files are stored. All paths can be set relative from the virtual directory. That means you can include "/myproject/myfile.asp", whereas in PHP it's often done using relative paths. Global.asa then contains global configuration for the application. You hardly ever have to worry about relative paths in the code.
In PHP you'd have include(dirname(FILE) . '/../../myfile.php") which is of course fugly. The only 'solution' I found for this is making HTML files and then using SSI (server side includes).
The only downside to ASP is the availability, since it has to run on Windows. But ASP files just run, and there's not complex Linux configuration to worry about. The language VBScript is extremely simple, but you can also choose to write server side JavaScript, since you're familiar with C.
I think you need to focus on Restful web applications. Zend is a PHP based MVC framework.
I am very new to python and having to get into this stuff for a simple program to integrate with an ASP.NET application that I am building. The pseudo code is as follows.
Get two parameters from request. (A ASP.NET will be calling this url by POST and sending two parameters)
Internally execute some business logic and build some response.
Write the response back so that the ASP.NET app can proceed.
Step 2 and 3 are already in place and working too but not able to find a solution for Step 1 (I know it should be very simple and know how to do it in Java/.NET/PHP and RoR but not in Python and the online docs/tutorials are not helping my cause). I am running python on apache using mod_python.
Any help here is greatly appreciated. Thanks in advance
Vijay
Here is a good beginner's tutorial for mod_python.
As far as I understand your question you have a mod_python-based script and you want to read a POST parameter. Therefore you only have to use the form object which is automatically provided by mod_python:
myparameter = form.getfirst("name_of_the_post_parameter")
You can find the documentation over here.
Note that this solution is when your server is configured with PythonHandler mod_python.psp which will allow you to use "Python Server Pages" (special <% %> tags, automatically created variables like form, ...). If you're writing a normal mod_python handler, then it would look something like that:
from mod_python import util
def handler(req):
form = util.FieldStorage(req, keep_blank_values=1)
myparameter = form.getfirst("name_of_the_post_parameter")
...other stuff...
"I know it should be very simple and know how to do it in Java/.NET/PHP and RoR but not in Python"
Well, it's not simple in Python -- the language.
It is simple in many Python web frameworks.
Don't make the mistake of comparing Python (the language) with PHP (the web framework) or RoR (the web framework).
Python, like Java or VB or Ruby, is a programming language. Not a web framework.
To get stuff from Apache into Python you have three choices.
A CGI script. A dreadful choice.
mod_python. Not a great choice.
mod_wsgi. A much better choice.
If you're stuck with mod_python -- because this is homework, for instance -- you'll need to read a mod_python tutorial in addition to a python tutorial.
This, for example, seems to be what you're doing. http://www.modpython.org/live/current/doc-html/tut-pub.html