last day (15 days later) » 

8:42 PM
2
A: When trying to run a Django project I get the NoReverseMatch error

Rohit JainYou're trying to reverse the url for 'views.helloworld'. But, that's not the name of the url you've defined. That's the view name. Change your urls.py file to: url(r'^$', views.hello_world, name='hello_world'), and then use: <a href="{% url 'hello_world' %}">Home</a>

 
Thanks! I edited the code as follows: from django.conf.urls import include, url from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns from . import views urlpatterns = [ url(r'^courses/', include('courses.urls', namespace='courses')), url(r'^admin/', include(admin.site.urls)), url(r'^$', views.hello_world, name='hello_world'), <a href="{% url 'hello_world' %}">Home</a> ] urlpatterns += staticfiles_urlpatterns() But it is giving a syntax error now.
 
Did you put <a href...> code inside urls.py?
 
Thanks. Yes I did.. As mentioned in the comment above.But it is not working
 
@ledzee That has to go in your html file. Replace the current href tag.
 
Thanks. This is my layout.html file now {% load static from staticfiles %} ........ <nav> <!-- <a href="{% url 'hello_world' %}">Home</a> --> <a href="{% url 'hello_world' %}">Home</a> <a href="{% url 'courses:list' %}">Courses</a> </nav> {% block content %}{% endblock %} </div> </body> </html> Its showing the NoReverseMatch error again.
 
8:42 PM
@ledzee Please post your update files in question. It's difficult to read code in comments.
 
I changed the question to newest code changes.
 
@ledzee Are you getting the ReverseMatch error for same url? or courses:list url?
 
Hi Rohit
Thanks for all the help
I am still getting the NoReverseMatch error
If you are willing I can send you the complete files as well
you can run it in your environment
 
Post the exact error you're getting now
 
NoReverseMatch: Reverse for 'views.hello_world' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
 
8:46 PM
Your template isn't updated it seems. It's still trying to reverse views.hello_world
 
hmm
how can I update it then..
 
where is your template file?
 
sorry for my illiteracy
i have a folder called templates
and i have 2 html files in it
home and layout
 
Please see that changes in layout.html is saved.
 
They are definitely saved
i checked again.. the same error
 
8:51 PM
Please post the template code here.
 
{% load static from staticfiles %}

<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
<div class="site-container">
<nav>
<!-- <a href="{% url 'views.hello_world' %}">Home</a> -->
<a href="{% url 'hello_world' %}">Home</a>
<a href="{% url 'courses:list' %}">Courses</a>
</nav>
{% block content %}{% endblock %}
</div>
</body>
</html>
 
Remove that commented <a href line from there.
 
ok..
 
Django will try to resolve the {% url %} tags before rendering the HTML page. So, even though you comment that out, it still tries to reverse the url
 
ok
i should delete it?
 
8:53 PM
Yes
 
ok
and run again?
Thanks Rohit!
You are a savior
i dont know how can i thank you :)
votting your answer as best for sure :)
 
You're welcome :)
 
I have a small question
 
sure
 
i have to deploy this application on AWS (amazon web services) for class project
I am not sure how to approach it
any tips?
 
8:59 PM
You can run this under a gunicorn server running behind nginx
 
Great! Thanks very much
I will do that
 

last day (15 days later) »