(English) Medium Clone Part 1: User Registration

Rất tiếc, mục này chỉ tồn tại ở Tiếng Anh (Mỹ). For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

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.

 #from project.urls

urlpatterns = [
url(r'^admin/', admin.site.urls),
url('', include('app.urls'))

#from app.urls

urlpatterns = [
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 ‘^$’.


The other thing that gave me a little trouble was remember to set the enctype properly so that I could retrieve the avatar image to save to the user.
Other than that, things went well overall. It was slow getting started though. Trying to remember exactly what needed to be done to register a new user was a bit of a challenge.
Next steps will probably be setting up the login/logout stuff.