I am working on django project(which is at verge of completion) and I have structure like something below: project name: Mysite App name: myapp
project urls : 127.0.0.1/myapp/blog etc
my requirement is to exclude my app from website (through out) and adding usernames in profile page like:
- 127.0.0.1/blog
- 127.0.0.1/products
- 127.0.0.1/search
and for profile page: 127.0.0.1/simer123/myprofile
I have took from various SO questions and able to exclude the "myapp" part from my urls. and Also able to include "username" in url for specific page. SO question1 SO question2 these questions really helped and I found a way out to include user name in my url.
But now again I am stuck because throughout the project I have used things like:
return HttpResponseRedirect(reverse_lazy('myapp:myprofile'))
And similarly in template part like:
<a href="{% url 'myapp:myprofile' %}">
How can I manage to convert them?
Can Anyone explain this with some example.
Thanks
Update: urls.py file in mysite folder looks like below:
urlpatterns = [
url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^$', 'myapp.views.index'),
url(r'^', include('myapp.urls', namespace="myapp")),
url(r'^myapp/', include('myapp.urls', namespace="myapp")),
url(r'^admin/login', adminLogin),
#url(r'^static/(?P<path>.*)$', views.serve),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
url(r'^(?P<username>\w+)/', include('myapp.urls', namespace="myapp")),
url(r'^(?P<username>\w+)/myapp/', include('myapp.urls', namespace="myapp")),
]
urls.py in myapp folder includes urls like below:
urlpatterns = [
# ex: /myapp/
url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^$', views.index, name='index'),
url(r'^about/$', views.about, name='user_about'),
url(r'^login/$', views.login, name='login'),
url(r'^newaccount/(?P<uid>.*)/$', views.newaccount, name='newaccount'),
url(r'^logout/$', views.logout, name='logout'),
url(r'^myprofile/$', views.profile, name='profile'),
]