These are chat archives for django/django

13th
Jan 2016
Nicholas Penny
@nickpennyuk
Jan 13 2016 18:24
Hi, I have an error that has stumped me
I am fairly new, have finished a django tutorial and am now taking the next steps by myself to learn from here on. When adding {% url 'artist_new' %} to an anchor in my HTML I'm getting a NoreverseMatch highlighting the above django url. Any thoughts?
ikhahmedov
@ikhahmedov
Jan 13 2016 18:30
search for name='artist_new' in your urls.py file, if no then you didn't specify url name, which {% url ... %} tag uses
@nickpennyuk
Nicholas Penny
@nickpennyuk
Jan 13 2016 18:33
U
ikhahmedov
@ikhahmedov
Jan 13 2016 18:33
urlpatterns = [
    ....
    url(r'blablabla', yourview, name='artist_new')
]
kdelinx
@kdelinx
Jan 13 2016 18:35

@nickpennyuk you should using namespace with name, for example:
url(r'^new/', include('users.urls', namespace='user')),

and such as urls in app:
url(r'^profile/$', 'profile', namespace='profile'))
so, after this, you can paste url -> {% url 'user:profile' %}

Nicholas Penny
@nickpennyuk
Jan 13 2016 18:42
@ikhahmedov its actually {% url 'artist_edit' %} and my url is:
url(r'^artist/(?P<pk>[0-9]+)/edit/$', views.artist_edit, name='artist_edit'),
ikhahmedov
@ikhahmedov
Jan 13 2016 18:42
then you should do
{% url 'artist_edit' pk=someid %}
kdelinx
@kdelinx
Jan 13 2016 18:42
@nickpennyuk YOU SHOULD paste NameESpACE
:)
@ikhahmedov Right:)
ikhahmedov
@ikhahmedov
Jan 13 2016 18:43
@kdelinx: @nickpennyuk is right, you can use namespace also, which will make your code much cleaner
otherwise you will encounter situation where you will define name='appname_subpart_edit', name='loooonglongname__longpart__......'
Nicholas Penny
@nickpennyuk
Jan 13 2016 18:45
@ikhahmedov @kdelinx Like i said, im new. Just trying to get the very basics down first, then worry about being pcky in the future.
ikhahmedov
@ikhahmedov
Jan 13 2016 18:46
@nickpennyuk than good luck, by the way I am also beginner, just 2 or 3pages ahead of you probably :)
Nicholas Penny
@nickpennyuk
Jan 13 2016 18:48
@ikhahmedov Thanks :)
@ikhahmedov @kdelinx I have never heard of namespace. any chance of an explanation or example using my url?
ikhahmedov
@ikhahmedov
Jan 13 2016 18:56

@nickpennyuk

url(r'^new/', include('users.urls', namespace='user')),
and such as urls in app:
url(r'^profile/$', 'profile', namespace='profile'))
so, after this, you can paste url -> {% url 'user:profile' %}

copy/paste from @kdelinx 's code with better formatting

as you already said, just dont use namespace for now ;)