You are not logged in.

  • Index
  •  » Django
  •  » Using Robots.txt file under Django in WebFaction

#1 2007-07-26 09:28:01

Nino
Member
From: Boston, MA
Registered: 2007-07-26
Posts: 3

Using Robots.txt file under Django in WebFaction

Does anyone have an example of using their Robots.txt file under Django that they would like to share?

I tried to just make a static app, but I'm already up to my allowed 3 apps.

Do I just copy the txt file to my templates directory and have a Render_to_response in view.py point to it?  Or will that treat it as an html file and try to render the text?

-Nino

Offline

 

#2 2007-07-26 10:13:48

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Using Robots.txt file under Django in WebFaction

You should be able to get the desired affect using django.http.HttpResponse so long as you specify a MIME type, ala:

Code:

from django.http import HttpResponse

def robots(request):
    return HttpResponse(open('robots.txt').read(), 'text/plain')

I imagine you could also do it in httpd.conf using the FilesMatch directive.


-David Sissitka

Offline

 

#3 2007-07-26 13:38:28

Nino
Member
From: Boston, MA
Registered: 2007-07-26
Posts: 3

Re: Using Robots.txt file under Django in WebFaction

Thanks David, but it's doing the same thing as just pointing to it as a template.  It's rendering it in HTML. 

So when you go to the site:
http://www.ninosystems.com/robots.txt

it shows:

User-agent: * Disallow: /


on one line...  That might be okay, but I just want to be really sure, since the spec is very specific about spaces and line returns.

Anyone know if this is okay or how to test this?

Offline

 

#4 2007-07-26 13:48:25

Nino
Member
From: Boston, MA
Registered: 2007-07-26
Posts: 3

Re: Using Robots.txt file under Django in WebFaction

Actually, you were correct.

It's strange but sometimes, even though I do a stop and start, it take a few minutes to see the results of a change.  I was still seeing the results of what I had done before I tried your code.

Thanks for the help David!

-Nino

Offline

 

#5 2007-07-26 20:23:01

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Using Robots.txt file under Django in WebFaction

Glad to see that you got things sorted out.

Just curious, are you using Firefox? If so sometimes a hard refresh isn't enough for its overzelous cache and you've got to do a Ctrl + Shift + Del.


-David Sissitka

Offline

 

#6 2007-08-10 13:09:41

kent37
Member
From: New Hampshire
Registered: 2007-02-17
Posts: 31
Website

Re: Using Robots.txt file under Django in WebFaction

Nino wrote:

Does anyone have an example of using their Robots.txt file under Django that they would like to share?

I tried to just make a static app, but I'm already up to my allowed 3 apps.

You can serve static files from your own Apache. I have these lines in my httpd.conf:

Code:

# robots.txt
<Location "/robots.txt">
    SetHandler None
</Location>

alias /robots.txt /home2/blogcosm/webapps/django/htdocs/robots.txt

Offline

 

#7 2008-02-22 13:45:16

tworking
Member
Registered: 2008-02-01
Posts: 43

Re: Using Robots.txt file under Django in WebFaction

You can serve static files from your own Apache. I have these lines in my httpd.conf:

Code:

# robots.txt
<Location "/robots.txt">
    SetHandler None
</Location>

alias /robots.txt /home2/blogcosm/webapps/django/htdocs/robots.txt

I have this in mine:

Code:

# robots.txt
<Location "/robots.txt">
    SetHandler None
</Location>

alias /robots.txt /home2/mcf2008/webapps/media/robots.txt

# google webmaster 1
<Location "/google0aaa4416b9976615.html">
    SetHandler None
</Location>

alias /google0aaa4416b9976615.html /home2/mcf2008/webapps/media/google0aaa4416b9976615.html

# google webmaster 2
<Location "/googleb9d35d42e8b7ca8d.html">
    SetHandler None
</Location>

alias /googleb9d35d42e8b7ca8d.html /home2/mcf2008/webapps/media/googleb9d35d42e8b7ca8d.html

but with no success.

Also my django admin can't find it's css file. Is it a problem (or is it neccessary) that my static files application runs on /media and django is looking for it's css file at /media/css/changelists.css?

Thanks.

Offline

 

#8 2008-02-23 09:49:49

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Using Robots.txt file under Django in WebFaction

There were three problems:

1) You didn't restart Apache after changing httpd.conf.
2)

[mcf2008@web28 django]$ ./apache2/bin/stop
Stopped
[mcf2008@web28 django]$ ./apache2/bin/start
Syntax error on line 30 of /home/mcf2008/webapps/django/apache2/conf/httpd.conf:
Invalid command 'alias', perhaps misspelled or defined by a module not included in the server configuration
Restarted
[mcf2008@web28 django]$

3)

[mcf2008@web28 django]$ ls /home2/mcf2008/webapps/media/robots.txt
ls: /home2/mcf2008/webapps/media/robots.txt: No such file or directory
[mcf2008@web28 django]$

So I:

1) Added "LoadModule alias_module modules/mod_alias.so" to your httpd.conf.
2) Created robots.txt.

And now everything appears to be working as expected.

Hope it helps. smile

Last edited by IAIHMB (2008-02-23 09:50:17)


-David Sissitka

Offline

 

#9 2008-10-01 20:04:51

lanec
Member
Registered: 2008-10-01
Posts: 1

Re: Using Robots.txt file under Django in WebFaction

Is it possible for this method to be used to place a favicon.ico image?

If I follow these steps exactly the favicon.ico file is interpreted oddly.

Offline

 

#10 2008-10-01 22:17:30

likebike
Member
Registered: 2008-05-04
Posts: 263

Re: Using Robots.txt file under Django in WebFaction

Hi Lanec,

It looks like you figured it out.  I can see your favicon of the little house when I visit your site.  Would you mind posting the solution?

Regards,

~Chris Sebastian
(admin)

Offline

 

#11 2009-06-15 19:56:36

DiegoCerdan
Member
Registered: 2008-07-11
Posts: 26
Website

Re: Using Robots.txt file under Django in WebFaction

This solution worked for me for some time. Todaday I was checking output errors from apache. Robots.txt was not beeing served as static file. sad

Code:

LoadModule alias_module modules/mod_alias.so

<Location "/robots.txt">
    SetHandler None
</Location>

alias /robots.txt /home/diegocerdan/webapps/media/robots.txt

Code:

ls /home/diegocerdan/webapps/media/robots.txt
/home/diegocerdan/webapps/media/robots.txt

Its not beeing server here:

http://www.tuentifotos.com/robots.txt

But you can reach it from here:

http://www.tuentifotos.com/media/robots.txt


Maybe an update in Apache and mod_alias stopped working?

Offline

 

#12 2009-06-16 03:32:03

David L
Administrator
Registered: 2009-04-13
Posts: 530

Re: Using Robots.txt file under Django in WebFaction

If you check your error log, you'll see the problem:

Code:

.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

I added the header module to your httpd.conf and now it works smile

Offline

 

#13 2009-06-16 13:19:01

DiegoCerdan
Member
Registered: 2008-07-11
Posts: 26
Website

Re: Using Robots.txt file under Django in WebFaction

@David: Thank you!. The support in Webfaction is great!

@likebike: I am doing the same for favicon as for robots and seems its working. If you try to check it through Firefox you get crappy output because mime type is not set.

Code:

<Location "/robots.txt">
    SetHandler None
</Location>

<Location "/favicon.ico">
    SetHandler None
</Location>


alias /robots.txt /home/diegocerdan/webapps/media/robots.txt
alias /favicon.ico /home/diegocerdan/webapps/media/favicon.ico

http://www.tuentifotos.com/robots.txt
http://www.tuentifotos.com/media/robots.txt

http://www.tuentifotos.com/favicon.ico
http://www.tuentifotos.com/media/favicon.ico

Offline

 

#14 2009-06-23 15:15:41

dburke
Member
Registered: 2009-01-10
Posts: 5

Re: Using Robots.txt file under Django in WebFaction

DiegoCerdan wrote:

@likebike: I am doing the same for favicon as for robots and seems its working. If you try to check it through Firefox you get crappy output because mime type is not set.

I spent some time trying to get favicon working and finally realized that, at least for my setup, I had to have the favicon location and alias *below* the root django location directive.  Then to get the mime type correct in Firefox, add "ForceType image/vnd.microsoft.icon" to the favicon location.

Last edited by dburke (2009-06-23 15:16:38)

Offline

 

#15 2009-06-26 09:06:10

DiegoCerdan
Member
Registered: 2008-07-11
Posts: 26
Website

Re: Using Robots.txt file under Django in WebFaction

@dburke: Thanks it works for me! smile

Code:

<Location "/favicon.ico">
    ForceType image/vnd.microsoft.icon
    SetHandler None
</Location>

alias /favicon.ico /home/diegocerdan/webapps/media/favicon.ico

Offline

 

#16 2009-09-18 06:24:55

Parthian
Member
Registered: 2008-09-05
Posts: 44

Re: Using Robots.txt file under Django in WebFaction

I'm having a problem trying to do use robots.txt and favicon.ico on my Django site.

I have created robots.txt and favicon.ico and added them to my Media App (latter in subfolder /icons/)

If I use URL  media.username.com/robots.txt and  media.username.com/icons/favicon.ico   - I can see the text and image as expected. Good.

I updated the Httpd.conf with

Code:

<Location "/robots.txt">
    SetHandler None
</Location>
<Location "/favicon.ico">
    SetHandler None
</Location>
alias /robots.txt /home/username/webapps/djangomedia_staticcgi_sym/robots.txt
alias /favicon.ico /home/username/webapps/djangomedia_staticcgi_sym/favicon.ico

So this should redirect the URLs to the media folder to get the two files as appropriate

But I cannot see the favicon with the Website URL and adding robots.txt or icons/favicon.ico to the URL results in a 500. Checking the Apache Error log gives
/home/username/webapps/djangomedia_staticcgi_sym/.htaccess: Invalid command 'ExpiresActive', ...

I use an .htaccess file in the static media folder for ExpiresHeaders

Code:

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|swf)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
</FilesMatch>

Looking for help there is a suggestion that I require to add the following to my httpd.conf although oddly this was not suggested when I started using ExpiresHeaders and there have been no problems previously.

Code:

LoadModule expires_module modules/mod_expires.so
AddModule mod_expires.c

And I have been restarting Apache

With a little more digging I discovered that removal of the .htaccess allows the robots.txt to appear and for the favicon.ico to become visible with www.username.com/favicon.ico although it wasn't appearing as an actual favicon if you follow.

I think the expires_module is a red herring - I didn't need it before to use ExpiresHeaders
In summary, trying to redirect the two files via httpd with an ExpiresHeaders in the .htaccess of my Media causes a 500.


Also, I'm not sure of favicons are picked up automatically or if I also need to add <link rel="icon" href="favicon"....  to the HTML Template. I've added this anyway.

Any ideas?

Last edited by Parthian (2009-09-18 10:22:52)

Offline

 

#17 2009-09-19 09:45:47

seanf
Administrator
Registered: 2008-02-01
Posts: 1899
Website

Re: Using Robots.txt file under Django in WebFaction

The reason you need to add mod_expires to your httpd.conf is:

- Your aliases point to files in your media directory
- Your media directory contains a .htaccess file with directives provided by mod_expires
- Your private Apache will process the .htaccess file when it serves your aliases, so it needs to have mod_expires loaded to be able to interpret the directives.

Hope that helps!

Offline

 

#18 2009-09-19 13:46:18

Parthian
Member
Registered: 2008-09-05
Posts: 44

Re: Using Robots.txt file under Django in WebFaction

That's the trouble with finding solutions on forums - they tend not to age well. AddModule mod_expires.c  - is an out of date solution as Seanf explained on a Ticket answer. And I don't need the <link rel="icon"   HTML.  but Temp Files / Cache need to be cleared to see the favicon.

Great support.

Offline

 

#19 2009-09-20 08:27:45

EricBrian
Member
Registered: 2009-09-20
Posts: 8

Re: Using Robots.txt file under Django in WebFaction

I am having troubles with favicon.ico not showing. Here are the appropriate lines from http.conf. Anything stand out?

Code:

LoadModule alias_module modules/mod_alias.so

<Location "/favicon.ico">
    SetHandler None
</Location>

alias /favicon.ico /home/ericbrian/webapps/static_stuff/sae/images/favicon.ico

Thanks

p.s., after making these changes to my conf file, I did a restart twice.

Last edited by EricBrian (2009-09-20 08:29:14)

Offline

 

#20 2009-09-20 08:47:31

EricBrian
Member
Registered: 2009-09-20
Posts: 8

Re: Using Robots.txt file under Django in WebFaction

Actually, that did it. After I posted that previous comment, I realized that I had some conflicting data in the conf file and sure enough, after I removed it, the favicon showed up.

Thanks! smile

Offline

 

#21 2009-09-28 09:52:46

Asinox
Member
Registered: 2009-08-18
Posts: 87

Re: Using Robots.txt file under Django in WebFaction

Excellent smile
thanks!

Offline

 

#22 2009-11-05 17:44:51

tezro
Member
Registered: 2009-11-05
Posts: 2

Re: Using Robots.txt file under Django in WebFaction

Offline

 

#23 2010-02-15 18:23:43

pappjm
Member
Registered: 2010-02-15
Posts: 1

Re: Using Robots.txt file under Django in WebFaction

There's no need to go changing httpd.conf, you can just have Django serve it up directly...

Add this pattern to your root urlpatterns:

Code:

(r'^robots.txt$', direct_to_template, {'template':'robots.txt', 'mimetype':'text/plain'})

You'll need to add this import to urls.py:

Code:

from django.views.generic.simple import direct_to_template

Then just put your robots.txt into your templates path.
(Remember to restart Apache so the changes are noticed...)

Offline

 
  • Index
  •  » Django
  •  » Using Robots.txt file under Django in WebFaction

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson