1👍
✅
Try adding a ‘$’ to the end of your urls. Django tries to match the urls from first to last, and since your first regular expression matches the url you’re trying to visit, it doesn’t bother looking further and goes to it. The ‘$’ will end the regular expression.
urls.py
urlpatterns = [
url(r'^profile/(?P<username>[\w.@+-]+)$', views.UserDetailView.as_view(), name="viewprofile"),
url(r'^profile/(?P<username>[\w.@+-]+)/follow$', views.UserFollowView.as_view(), name="follow"),]
0👍
If the page “just refreshes”, it sounds like the button HTML itself is incorrect. I had this problem yesterday and after an hour of digging into my JS and Python, I realized that a button automatically submits a form on the page unless it is declared with the type “button” like this:
<button type="button" ....>
- Access request from the forms.Form to get data from dB related to user
- Access variables in the Redirect in django
- Passing JSON var in leaflet "on()" method
- Python if elif else only returning first output without using logic
- Django how to add taggit tags to model within template
Source:stackexchange.com