99👍
You should just change you action url in your template:
<form action="{% url 'submit' %} "method='post'>
On the note of url namespaces…
In order to be able to call urls using home
namespace you should have in your main urls.py file line something like:
for django 1.x:
url(r'^', include('home.urls', namespace='home')),
for django 2.x and 3.x
path('', include(('home.urls', 'home'), namespace='home'))
33👍
In your main project, open url.py first. Then check, there should be app_name declared at first. If it is not, declare it.
For example, my app name is user info which is declared in url.py
app_name = "userinfo"
urlpatterns = [
url(r'home/', views.home, name='home'),
url(r'register/', views.registration, name='register')
]
- [Django]-ImportError: No module named virtualenv
- [Django]-Django ignores router when running tests?
- [Django]-What does 'many = True' do in Django Rest FrameWork?
25👍
I also faced the same issue.
it is fixed now by adding
app_name = "<name of your app>"
in app/urls.py
- [Django]-Numeric for loop in Django templates
- [Django]-Django – Render the <label> of a single form field
- [Django]-DRF: Simple foreign key assignment with nested serializers?
9👍
For Django 3.0, if you’re handling your urls within the app and using include
with path
, in your project/urls.py
:
urlpatterns = [
path(os.getenv('ADMIN_PATH'), admin.site.urls),
path('', include('my_simple_blog.urls', namespace='my_simple_blog')),
path('account/', include('account.urls', namespace='account')),
]
You need to specify namespace
in include
.
And then in your app/urls.py
:
app_name = 'account'
urlpatterns = [
path('register/', registration_view, name='register'),
path('logout/', logout_view, name='logout'),
path('login/', login_view, name='login'),
]
The app_name
must match the namespace
you’ve specified in project/urls.py
.
Whenever you’re referring to these urls, you need to do it like this:
{% url 'namespace:name' %}
If you’re using it with redirect
:
return redirect('namespace:name')
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-What is the Simplest Possible Payment Gateway to Implement? (using Django)
- [Django]-Django Rest Framework with ChoiceField
9👍
For the namespace error,
Make sure you have linked the app’s url in the main urls.py file
path('app_name/',include('app_name.urls'))
also in the urls.py of your app,make sure you mention the app’s name as
app_name='app_name'
Also make sure you have registered the app’s name on your installed apps in settings.py
- [Django]-Modulus % in Django template
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
- [Django]-Django: Multiple forms possible when using FormView?
3👍
As azmirfakkri has said if you’re using redirect
, dont use this {% url 'namespace:name' %}
syntax, use return redirect('namespace:name')
.
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-When to use Serializer's create() and ModelViewset's perform_create()
- [Django]-How do I use Django groups and permissions?
3👍
Probably 2 things could be a root cause,
in app/urls.py do include as below
app_name = 'required_name'
and in project urls.py also include the app_name
url(r'^required_name/$',views.home,name='required_name'),
Check: register app in settings.py INSTALLED_APPS
- [Django]-Token Authentication for RESTful API: should the token be periodically changed?
- [Django]-Can't install via pip because of egg_info error
- [Django]-Printing Objects in Django
2👍
tag name must be unique in the urls.py
file inside your application package inside the project! it is important for the template tagging to route whats what and where.
now [1] inside the urls.py
file you need to declare the variable appName
and give it the unique value. for example appName = "myApp";
in your case myHomeApp and [2] also define the urlpatterns list…
urlpatterns = [..., url(r'^submit/$', views.submit, name='submit'), ...];
in the html file just change the url tag to:
<form action="{% url 'myHomeApp:submit' %}" method='post'>
this should sifuce… else just write here and we’ll see how to continue on
- [Django]-Add a custom button to a Django application's admin page
- [Django]-How do I migrate a model out of one django app and into a new one?
- [Django]-Django {% if forloop.first %} question
2👍
A common mistake that I always find is when you have some name space in your template,
and in YourApp.url you don’t have any name space so if you should use name space add
in YourApp.url something like this
app_name = “blog”
then on your temples make sure you add your name space,
so you will have some thing like this “assumption errors are coming from edit.html
”
then on that particular template you will do this
"{% url 'blog:vote' pk=post.pk %}"
"{% url 'blog:post_category' category.name %}"
- [Django]-How to get GET request values in Django?
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
- [Django]-Is virtualenv recommended for django production server?
2👍
if you happen to be nesting include(
s, the namespace compounds, eg. topappname:appname:viewname
- [Django]-How to set the timezone in Django
- [Django]-Why does Django's render() function need the "request" argument?
- [Django]-How to implement followers/following in Django
1👍
Maybe someone will find this suggestion helpful.
Go to your applications urls.py
and type this before the urlpatterns:
app_name = 'Your app name'
- [Django]-Django 1.7 migrate gets error "table already exists"
- [Django]-Overriding AppConfig.ready()
- [Django]-Django.db.utils.ProgrammingError: relation already exists
1👍
For anyone who struggled on this error like me: After reading the solutions to this question, I was setting namespace
in include
function in a wrong urls file. Make sure you are modifying the right urls file. For me it was putting it in the main url.py
besides settings.py
. I hope this answer helps anyone who was confused as I was.
- [Django]-Manage.py runserver
- [Django]-Django 1.5 – How to use variables inside static tag
- [Django]-Django form – set label
1👍
I got the same error below:
NoReverseMatch at /my_app1/
‘my_app1’ is not a registered namespace
So, I set account
to my_app1
in my_app1/urls.py
as shown below then the error was solved:
# "my_app1/urls.py"
from django.urls import path
from . import views
app_name = "my_app1" # Here
urlpatterns = [
path("", views.index, name="index")
]
- [Django]-Django exception middleware: TypeError: object() takes no parameters
- [Django]-How does one make logging color in Django/Google App Engine?
- [Django]-Itertools.groupby in a django template
1👍
Check your urls.py
urlpatterns = [
re_path(r'^submit/expense/$', views.submit_expense, name='submit_expense'),
re_path(r'^submit/income/$', views.submit_income, name='submit_income'),
re_path(r'^register/$', views.register, name='register'),
]
then open template.html
put for example register register in your HTML tag like this:
<a class="navbar-brand" href="{% url 'register' %}">
- [Django]-Django MEDIA_URL and MEDIA_ROOT
- [Django]-Django database query: How to get object by id?
- [Django]-Django – view sql query without publishing migrations
0👍
This worked for me:
In urls.py
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index),
path("test/", views.test, name = 'test')]
In views.py:
def test(request):
return render(request, "base/test.html")
In the template:
href="{% url 'test' %}"
- [Django]-Using Cloudfront with Django S3Boto
- [Django]-Django REST Framework : "This field is required." with required=False and unique_together
- [Django]-How to go from django image field to PIL image and back?
0👍
I fixed it by using this on my main app’s urls so when I use this way This error disappear
In the main folder, where the setting is there, go to urls and
path("" , include("YourAppName.urls"))
,
- [Django]-How to get the username of the logged-in user in Django?
- [Django]-How do I use django rest framework to send a file in response?
- [Django]-Django Setup Default Logging