I have created a django project called "blogprojesi". I want to import the urls.py file inside the application I created with the name "inf" to the urls.py file inside this project, but I am getting the following error ImportError: cannot import name 'inf' from 'blogprojesi' (.....\blogprojesi\blogprojesi_init_.py)
I guess somehow it doesn't see the inf app. I tried the Re_path thing but it didn't work. How can I solve this?
**urls.py file inside the "blogprojesi"**
from django.contrib import admin
from django.urls import path,include
from blogprojesi import inf
from blogprojesi.inf import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('',inf,include('inf.urls')),
]
**Contents of urls.py file inside inf application**
from django.urls import path
from . import views
urlpatterns = [
path("",views.index),
path("index",views.index),
path("blogs",views.blogs),
path("blogs/<int:id>",views.blog_details),
]
**Contents of views.py file inside inf application**
from http.client import HTTPResponse
from django.http.response import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse("Home Page")
def blogs(request):
return HttpResponse("blogs")
def blog_details(request,id):
return HttpResponse("blog detail: "+id)
If I understand well your project structure and your question, you have a project named blogprojesi and an application called inf. There is no need to import urls in this way, it can and usually is done differently.
So, in your blogprojesi/urls.py file you should have something like thins (together with other stuff that you need):
from django.contrib import admin
from django.urls import path,include
from blogprojesi.inf import urlpatterns as inf_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
] + inf_urlpatterns
And the inf/urls.py could remain as is. I haven't tested this, but it should work. There are also other possibilities, but this should work.
BTW, your code may also work, but the path that includes urls from inf application has a mistake. Maybe something in line with this might work:
re_path('', include('inf.urls'))
Hope this helps.