0

My Url conf is as follows

url(ur'^phrase/(?P<lang>[_A-Za-z]+)/(?P<phrase>[%A-Za-z0-9]+)/$', 'gs.langdb.views.phrases'),

Views.phrases returns JSON object

def phrases(request,lang,phrase):                                                               
langs = Langauges.objects.all().values(
    'language',
    'lang_code')
lang_list = []
try:                                              
    map(lambda x: lang_list.append(x),langs)
    json = simplejson.dumps(lang_list)
    return HttpResponse(json, mimetype='application/json')
except TypeError:
    print "Can't convert language to Json \n"

My View is as follows:-

$("#phrase").autocomplete({
    source: function(request,response){
        var selectedValue = document.getElementById("language").value;
        $.ajax({
             url: "/phrase/"+selectedValue+"/"+request.term,
             dataType : 'json',
             type : 'GET',
             data : {},
             success : function(data,selectedValue) {

             }
       });
    },
});

<div class="ui-words">
       <label for="phrase">Input word: </label>
       <input id="phrase">
</div>

String which i used for testing, अनिश

Error which i have got in the server log

"GET /phrase/Mr_in/%E0%A4%85%E0%A4%A8%E0%A4%BF%E0%A4%B6 HTTP/1.1" 404 2275

I am not sure whether where i need to specify encodings? Any help in this issue will be appriciated

anish
  • 1,035
  • 4
  • 13
  • 27

1 Answers1

2

try this url pattern:

url(r'^phrase/(?P<lang>[_A-Za-z]+)/(?P<phrase>([^/]+))/$', 'gs.langdb.views.phrases'),
sha256
  • 3,029
  • 1
  • 27
  • 32
  • THanks! but above expression is giving error as ImproperlyConfigured: "^phrase/(?P[_A-Za-z]+)/(?P([^//]+)/$" is not a valid regular expression: unbalanced parenthesis. How to specify esacape sqences in urls – anish Dec 11 '13 at 09:26
  • you missed a parenthesis before `/$`. copy the whole line from my code. you don't need to escape `/` – sha256 Dec 11 '13 at 10:35