0

I am trying to build my urls dynamically upon my project execution, it retrieves all my projects and concatenates the strings to create the urls like following:

for project in projects: 
    domain = Settings.objects.get(id_project=project).site_domain
    urlpatterns +=  patterns('',
    (r'^'+project.type+r'/'+project.name+r'/', include('apps.'+project.type+'.urls')))

The problem is that django is generating me this error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 144: ordinal not in range(128)

and when I take a look at the stack, there is nowhere pointing to my code.. I believe it has a relation to the r'^' which could be a different type of encoding, but I couldn't find resources to draw any conclusion.

Any help is extremely appreciated

bobleujr
  • 1,179
  • 1
  • 8
  • 23
  • You can safely replace `r'^'` and `r'/'` with `'^'` and `'/'`. The `r` doesn't do anything unless there are backslashes in the string. – Dietrich Epp Oct 13 '16 at 15:07

1 Answers1

1

Is that patterns a typo?

for project in projects: 
    domain = Settings.objects.get(id_project=project).site_domain
    urlpatterns +=  url(r'^'+project.type+r'/'+project.name+r'/', include('apps.'+project.type+'.urls'))
itzMEonTV
  • 19,851
  • 4
  • 39
  • 49