1

I have created a signed token using Django in order to create a URL for validating email addresses. I now need to ensure my urlpattern matches the token Django creates.

The token is created using the following function:

from django.core import signing

def create_token(verify_code, partial_token):
   token = {
      'verify_code': verify_code,
      'partial_token': partial_token
   }
   return signing.dumps(token)

And I have the following url + regex:

url(r'^email/validation/(?P<signed_token>[^/]+)/$', core_views.email_validation,
    name='email_validation')

Is (?P<signed_token>[^/]+) the correct regex to pickup all possible tokens created using that function.

Rob
  • 567
  • 3
  • 13
  • And what is your question? Or error if any? – Jan Oct 13 '17 at 12:38
  • My question is - is that the correct regex for the token produced by the signing function? (I am pretty inexperienced with regards to regex) – Rob Oct 13 '17 at 13:15

1 Answers1

1

The token generated by Django will be a base 64 string. You could find a regex to specifically match base 64, but this is unnecessary unless you have other URL patterns that could conflict with this one (and if you do, the better solution would be to modify your URL patterns).

The regex you currently have is simply catching all characters that aren't a /, which should work just fine.

solarissmoke
  • 24,362
  • 12
  • 56
  • 60
  • Awesome, thanks for that. I don't have any URL patterns that would conflict with this so that's perfect. – Rob Oct 14 '17 at 12:27