I tried to change setting to below but doesn't work:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp']
my directory:
manage.py
django_project
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
myapp
migration
__init__.py
admin.py
apps.py
models.py
tests.py
urls.py
views.py
it keeps showing ModuleNotFoundError: No module named 'myapp.urls'
views.py from myapp:
from django.shortcuts import render, Httpresponse
def index(request):
HttpResponse('Welcome!')
urls.py from myapp:
from django.urls import path
urlpatterns = [
path('', views.index ),
path('create/', views.index)
path('read/1/', views.index)
]
urls.py from django_project:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls'))
]
Thank you!
Try adding
in myapp/apps.py
from django.apps import AppConfig
class MyAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'
Maybe you need to set this ?
Docs
Related
thanks for reading.
When I run "py manage.py makemigrations" I get the following message:
"ModuleNotFoundError: No module named 'transformaTe'"
This is the apps.py code:
from django.apps import AppConfig
class TransformateConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'transformate'
The name is updated there and in my INSTALLED_APPS:
INSTALLED_APPS = [
'transformate',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Where else should I look to change the name of the app?
This is the simplified structure of the app:
\my-app
\transformate
admin.py
apps.py
models.py
urls.py
views.py
\my-app
asgi.py
settigs.py
urls.py
wsgi.py
All this happened when I rename the app because I had a problem creating a table called transformaTe_myuser so I though all could be caused by the capitalized letter use.
Is there a better way of renaming an existing app in Django? I followed this steps, except for the migration part (Because I deleted the db and the migrations folder):
https://odwyer.software/blog/how-to-rename-an-existing-django-application
Thanks for your help.
Well, it turns out that when you run makemigrations you have to check the project urls.py file, that was the only thing that was crashing my migrations.
ORIGINAL my-app/urls. py FILE:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('transformaTe.urls')),
path('admin/', admin.site.urls),
]
NEEDED FILE:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('transformate.urls')), # Here was the bug
path('admin/', admin.site.urls),
]
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return HttpResponse("Hellow, World !")
from django.urls import path
from . import views
urlspattern=[
path("",views.index,name="index")
]
from django.contrib import admin
from django.urls import include,path
urlpatterns = [
path('admin/', admin.site.urls),
path("hello/", include("hello.urls"))
]
INSTALLED_APPS = [
'hello',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Error I am gettting is
Using the URLconf defined in helloproject.urls, Django tried these URL patterns, in this order:
admin/
The current path, hello/, didn't match any of these.
you have a typo error on urlpattern
urlspattern=[
path("",views.index,name="index")
]
you have to change that to
urlpatterns=[
path("",views.index,name="index")
]
In this line change urlpattern to urlpatterns
urlpatterns=[
path("",views.index,name="index")
]
I am getting errors in almost all imports please help.
i'm using django 2.2.5, python 3.7, but getting errors in unresolved import'django.contrib' ,unresolved import'django.urls',unresolved import'django.shortcuts' etc
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path("", include("hello.urls")),
path('admin/', admin.site.urls),
]
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
Message=No module named 'django'
File "C:\Users\Sharf\Desktop\python projects\p1\calc\urls.py", line 1,
in <module>
from django.urls import path
Can you post your settings.py file ? I think the problem comes from here ...
INSTALLED_APPS = [
'mainApp.apps.nameApp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels'
]
ROOT_URLCONF = 'app.urls'
I have created a directory called vsdk which includes service_development (a voice application) and my newly created application called dashboard. Unfortunately I can’t seem to get the main page of dashboard to work. I get a 404 error when trying to access 127.0.0.1:8000/dashboard/, while doing everything similar to what I’ve done with service_development.
Would someone be able to help me?
Vsdk\settings.py
INSTALLED_APPS = [
'vsdk.service_development.apps.ServiceDevelopmentConfig',
'vsdk.dashboard.apps.DashboardConfig',
'storages',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Vsdk\dashboard\apps.py
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class DashboardConfig(AppConfig):
name = 'vsdk.dashboard'
verbose_name = _("Dashboards")
Vsdk\urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.urls import include, path
admin.site.site_header = _("Petrichor Rain Service")
urlpatterns = [
url(r'^', admin.site.urls),
url(r'^vxml/', include('vsdk.service_development.urls')),
url(r'^vxml/', include('vsdk.dashboard.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Vsdk\dashboard\urls.py
from django.shortcuts import render
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
I have issues importing my app in url patterns, but everything seems in place. I get errors in from fairy_app import views and an error name 'News' is not defined
directory:
fairy-
fairy-
_init_.py
settings.py
urls.py
wsgi.py
fairy_app-
_init_.py
admin.py
models.py
tests.py
views.py
db.fairy
manage.py
views.py
from django.shortcuts import render
from django.views.generic import TemplateView
# Create your views here.
class News(TemplateView):
template_name = 'news.html'
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from fairy_app.views import News
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'fairy.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^news/', News.as_view()),
)
setting.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'fairy_app',
)
In your urls.py you reference the News view without importing it. You import the views file as module.
So you can either do:
views.News.as_view()
or:
from fairy_app.views import News
2nd way is shorter but gets inconvenient if you have many view classes, so I prefer the first one.
I found the same problem,but got sorted it out.
Create a new python file in app-level for urls
use include function in fairy-/urls file to include all other urls of the app and import views in the new file
for example;
#in url.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^greet/',include('greetings.url')),
]
#created a new file(url.py) in greetings app
#in greetings/url.py
from . import views
urlpatterns = [
url(r'^$',views.greet),
]
#greet is the function in my views`
I had the same problem. I worked around it by giving the full path
from fairy.fairy_app.views
alternatively
from ..fairy_app.views