1

I was wondering how to make links like this - www.google.com/search

Is '/search' a directory? I really need help with this. I'm willing to make a website in Python, and sort of novice in Python.

Like, I want to print this - http://www.mywebsite.com/search

Do they use .htaccess for this purpose?

Thanks.

2 Answers2

0

If you want to try using Flask, you will use what are called "routes" to define the various pages where you content can live.

In your example, they have defined a route called /search, which will then serve up some content.

Here's another example in the Flask documentation: http://flask.pocoo.org/docs/0.10/quickstart/#routing

It isn't the same as what you might be used to if you ever made a website using FTP and plain old html, where you might have a URL like www.mywebsite.com/code/ranjan.html. In that case, the URL actually was pointing to folders and files.

But the "new" way (the good, proper way) is to use URL routing with nice clean URLS to point to your content.

You might also like to try to read the section in the Django documentation about url dispatching to give you more ideas. (Django is another Python framework for making websites.)

Edit: As to your question about .htaccess, yes, you can do URL rewrites using .htaccess, but Flask, Django and other web frameworks will save you from needing to do that. Here is an example.

Community
  • 1
  • 1
supermitch
  • 2,062
  • 4
  • 22
  • 28
0

No, most likely search in that instance is not a directory. It is a URL that is mapped to call some function on a server that returns a response to the client. A simple example in the Python framework Flask would look like this:

@app.route('/search')
def search():
    # search for some stuff
    return some_response # how you would go about doing this will vary depending on your application.

So when your server receives a request to the /search URL the code in your search() function would be executed. This is done differently in different frameworks but the concept is the same:

  • Your server receives a request on a URL
  • You application finds the URL in your URL configuration (decorated functions in Flask, a urls.py file Django etc.)and the method/function it is mapped to
  • It executes the function and returns the result in the way you have defined

This is the way that Flask, Django, Bottle and Pyramid work for the most part (there are many differences but the idea is the same) and I'm sure it's the same in many other languages and frameworks.

I would suggest learning Flask or Bottle to get started as they are both pretty simple. Django is much mroe complicated but the tutorial on the site is pretty good.

kylieCatt
  • 10,672
  • 5
  • 43
  • 51