Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: ordering of allow and disallow rules #80

Open
michaelsstuff opened this issue Nov 30, 2017 · 1 comment
Open

Feature request: ordering of allow and disallow rules #80

michaelsstuff opened this issue Nov 30, 2017 · 1 comment

Comments

@michaelsstuff
Copy link

Allowing to set the order of allow and disallow rules would be helpful.
As far as I know google does not care for the order, but other do, as speicied in the draft for robots.txt:
http://www.robotstxt.org/norobots-rfc.txt -> 3.2.2 The Allow and Disallow lines

To evaluate if access to a URL is allowed, a robot must attempt to
match the paths in Allow and Disallow lines against the URL, in the
order they occur in the record. The first match found is used.

@some1ataplace
Copy link

Create a new model in your models.py file extending the robots.models.Rule class. Apply the required ordering logic by adding the ordering option in the Meta class.

from django.db import models
from robots.models import Rule

class CustomRule(Rule):
    order = models.PositiveIntegerField(blank=True, null=True)

    class Meta:
        ordering = ['order']

Create a admin.py file in your app directory, and register the new CustomRule model with the Django admin.

from django.contrib import admin
from robots.admin import RuleAdmin
from .models import CustomRule

@admin.register(CustomRule)
class CustomRuleAdmin(RuleAdmin):
    pass

Manage the ordering of allow and disallow rules in the Django admin site. Remember that you will need to create a new migration for the new CustomRule model and apply it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants