简体   繁体   中英

Django URL use string in regex

Currently my regex takes a question id like so (working):

url(r'^(?P<college_id>[0-9]+)/$', views.detail, name="detail")

But I want it to instead take college_name which is a string with no spaces. How would I set that up?

You could use r'^(?P<college_name>\\w+)/$'

This is a great tool for testing regular expressions: https://regex101.com/r/q6fWPl/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM