I’ve worked my way through a few django tutorials and videos and decided that I should have seen enough to be able to make a medium clone. These next series of posts will be about how I went about tackling the problem and me just taking notes on some of the things that gave me trouble.
I decided that I would start with user registration, but before getting to that, I had to set up my home page and registration pages. I went through the basic process of creating my views, templates, and setting up the urls.py file. That’s where I met my first problem.
url(r'^$', views.WelcomeView.as_view(), name='welcome'),
url(r'^register/$', views.register_blogger, name='register')
r” vs r’^$’
I wasn’t really sure how they were different at first. I’ve seen both used, but I didn’t spend the time understanding what they we’re doing. Both were basically searching for empty strings. The difference is the ^ and $ are special regex characters. ^ matching the beginning of a string and $ matching the end. Which means this is looking for an empty line. Where ” looks for empty strings anywhere in the url, which apparently is true for every url. So, in my project.urls, I can use that to reroute every non-admin url to my app.urls, but if I want to match my welcome page, then I have to use the ‘^$’.