A
A
Andrey2015-12-03 20:50:21
Django
Andrey, 2015-12-03 20:50:21

How to resolve conflict between user slug and service slug?

Hello!

urlpatterns = [
    url(r'^register/$', UserSignup.as_view(), name='signup'),
    url(r'^login/$', UserLogin.as_view(), name='login'),
    url(r'^logout/$', UserLogout.as_view(), name='logout'),
    url(r'^edit/$', UserSettings.as_view(), name='settings'),
    url(r'^feedback/$', Feedback.as_view(), name='feedback'),
    url(r'^(?P<slug>[-_\w]+)/$', UserDetail.as_view(), name='user_detail'),
]

If the user fills in the servants with one of the service names (for example: feedback) , then he will no longer get on his profile!
Doing url(r'^ user/ (?P[-_\w]+)/$', UserDetail.as_view(), name='user_detail') is somehow not very nice.
Do some extra validation on the form to check if the slug matches?
What do you advise? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zigen, 2015-12-03
@andrey_u

There was a similar situation. We check the user's slug field for matches with prohibited names in the user registration form:

class UserRegForm(AuthentificationForm):
...
    def clean_slug(self):
        slug = self.cleaned_data.get('slug')
        if slug in settings.PROHIBITED_NAMES:
            raise forms.ValidationError(u'Данное название уже было зарезервировано')
        return slug

In settings or in any other place, we store a list of prohibited slugs (look in your url pattern):
PROHIBITED_NAMES = ('article', 'accounts', 'admin', 'ckeditor',....)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question