Django accepts get parameters

The error can be seen here: http://djaffry.selfip.com:8080/

I want the index page to accept parameters, whether

mysite.com/search/param_here

or

mysite.com/?search=param_here

I have this in my URL patterns, but I can't get it to work. Any suggestions?

urlpatterns = patterns('',
        (r'^$/(?P<tag>\w+)', 'twingle.search.views.index'),
    )
+3
source share
1 answer

First of all, your regular expression in the url pattern is incorrect.

r'^$/(?P<tag>\w+)'

It says that you need to combine everything:

  • ^ start of line
  • $ to end of line
  • having a template with a name that consists of words and numbers after the end of the line

Usually, after the end of one line, another line or EOF appears, and not the content (unless you use a multi-line regular expression and you don't need it here).

:

r'^/(?P<tag>\w+)$'

reslover URL.

, URL- :

http://mysite.com/?query=param_here

:

(r'^$', 'twingle.search.views.index')

query :

request.GET.get('query', '')

mysite.com/search/param_here 

:

(r'^search/(?P<query>\w+)$', 'twingle.search.views.index'),

, \w ( , ), query.

url:

urlpatterns = patterns('twingle.search.views',
   url(r'^$', 'index'),
   url(r'^search/(?P<query>\w+)$', 'index'),
)

:

def index(request, query=None)
    if not query:
       query = request.GET.get('query', '')
    # do stuff with `query` string
+22

Source: https://habr.com/ru/post/1746741/


All Articles