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'),
]
Related
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'm new to django so take me easy. I'm just following some youtube tutorials and try to make a simple app to print Hello on the browser with django. And I keep getting this error in the urls.py file
ModuleNotFoundError: No module named 'app'
I get this error in urls.py file of my project which is bellow:
urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('app.urls')),
path('admin/', admin.site.urls),
]
I also made an app called app
app\urls.py
from django.urls import path
import views
urlpatterns = [
path('', views.home, name = 'home'),
]
app\views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse('Hello!')
I read I think all threads on this topic and nothing helped so far and I can't realise where's my mistake or what I did wrong.
In your settings.py, add 'app.apps.AppConfig', in INSTALLED APP. You have to register the newly made apps to settings.py.
INSTALLED_APPS = [
'app.apps.AppConfig', // Added the name of app
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
]
*Note:- Everytime you add an app, register it in settings.py
I am trying to wire up a view based on the Django tutorial (1.8), and am for some reason not getting a basic url to work:
Page not found (404)
Settings
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'events',
)
In the main folder, I have these_events/these_events/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('events.urls')),
]
In the events app, I have these_events/events/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r"^$", views.search_db, name='search-db')
]
these_events/events/views.py:
from django.shortcuts import render
from django.http import HttpResponse
def search_db(request):
return HttpResponse("hello, world")
This has me befuddled as I followed the example, and this is the way I remember using Django in the past.
In these_events/these_events/urls.py
try changing
url(r'^/', include('events.urls')),
to
url(r'', include('events.urls')),
I have a django-oscar project I am working on. And I have been searching everywhere to solve this problem. Although, I have come across similiar questions here, I still can't solve the problem.
I am trying to create other pages such as 'about', and 'contacts'. I have checked the dashboard for pages creating but can't seem to do exact what I want. I want to be able put these pages on the footer area. I was able to display these pages created at the dashboard to my footer but it seems simple displaying just text. Was wondering if I could do more.
I have created an app in my apps folder. Here is the folder structure:
Here is my env installs -
pip freeze requirements.txt
Babel==2.3.4<
beautifulsoup4==4.5.1
colorama==0.3.7
coverage==3.7.1
coveralls==0.4.4
detox==0.10.0
Django==1.9.12
django-appconf==1.0.2
django-compressor==1.6
django-countries==4.0
django-debug-toolbar==1.5
django-extra-views==0.6.4
django-haystack==2.5.1
django-localflavor==1.3
django-nose==1.4.2
django-oscar==1.3
-e git://github.com/tangentlabs/django-oscar- paypal.git#76542cefa67170b10694ab431a0b35408d99b16e#egg=django_oscar_paypal
django-static-precompiler==1.5
django-tables2==1.0.7
django-treebeard==4.1.0
django-webtest==1.7.7
django-widget-tweaks==1.4.1
docopt==0.6.2
enum-compat==0.0.2
enum34==1.1.6
eventlet==0.20.0
factory-boy==2.7.0
fake-factory==0.7.2
flake8==2.2.3
funcsigs==1.0.2
greenlet==0.4.11
ipaddress==1.0.17
mccabe==0.5.2
mock==1.0.1
mod-wsgi==4.5.11
nose==1.3.7
pbr==1.10.0
pep8==1.7.0
phonenumbers==7.7.5
Pillow==3.4.2
pinocchio==0.4.1
pluggy==0.3.1
purl==1.3
py==1.4.31
pycountry==16.11.27.1
pyflakes==1.3.0
pytest==3.0.1
pytest-cov==2.3.1
pytest-django==3.0.0
python-dateutil==2.6.0
pytz==2016.10
PyYAML==3.12
requests==2.12.3
six==1.10.0
sorl-thumbnail==12.4a1
sqlparse==0.2.2
tox==2.1.0
Unidecode==0.4.19
virtualenv==15.1.0
waitress==1.0.1
WebOb==1.6.3
WebTest==2.0.16`
Here is myapp views.py
from django.http import HttpResponse
from django.core.urlresolvers import reverse
def about(request):
return HttpResponse(request, "my about page", {})
def contacts(request):
return HttpResponse(request, "my contact page", {})
Here is apps.myapp urls.py
from django.conf.urls import url
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns`
from . import views
from apps.myapp import views
urlpatterns = patterns ('',
url(r'^en-gb/contacts/', views.contacts, name='contacts'),
url(r'^/about/', views.about, name='about'),
)
here is mysite (root) urls.py
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
from apps.app import application
from paypal.payflow.dashboard.app import application as payflow
from paypal.express.dashboard.app import application as express_dashboard
admin.autodiscover()
from apps.app import myapp_o
'''everything else has to have the include apart from the admin'''
urlpatterns = patterns
[
'',
(r'^admin/', admin.site.urls),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^myapp_o/', include('apps.myapp_o.urls')),
]
urlpatterns += i18n_patterns('',
# PayPal Express integration...
(r'^checkout/paypal/', include('paypal.express.urls')),
# Dashboard views for Payflow Pro
(r'^dashboard/paypal/payflow/', include(payflow.urls)),
# Dashboard views for Express
(r'^dashboard/paypal/express/', include(express_dashboard.urls)),
(r'', include(application.urls)),
'''(r'^myapp_o/', include('myapp_o.urls')),'''
)
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Could anyone share and tell me where I am going wrong? Or is there a better was of doing this within the dashboard?
Thanks
Eve
Need to add information from my setting
import os
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.flatpages',
'django.contrib.staticfiles',
'mod_wsgi.server',
# External apps
# 1.5.7 still ships with South migrations in the wrong folder,
# 1.5.8 contains a fix. Upgrade when released.
# 'django_extensions',
'debug_toolbar',
# Apps from oscar
'paypal',
'compressor',
'widget_tweaks',
]
from oscar import get_core_apps
INSTALLED_APPS = INSTALLED_APPS + get_core_apps([
'apps.shipping',
'apps.checkout',
'apps.myapp',])
Thank you.
Let's check your code first:
on apps/myapp/urls.py, you should NOT import like this.
from . import views
from apps.myapp import views
Because later views overrides first views var. so your code should be changed with from . import views or from views import about, contacts to get clear import.
Second, after Django 1.8, urlpatterns does not use patterns anymore. you should consider to use url function to use your code after Django1.10(after 1.10 patterns is deprecated).
so your code can be changed like this:
urlpatterns = [
url(r'^en-gb/contacts/$', views.contacts, name='contacts'),
url(r'^about/$', views.about, name='about'),
]
I also add $ end of your url to exactly match url from user's request.
Third, when I searched django docs with i18n_patterns,
You can use django's urls with String include like include('paypal.express.urls').
I think your urls can be like this:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^myapp_o/', include('apps.myapp_o.urls')),
]
urlpatterns += i18n_patterns(
# PayPal Express integration...
url(r'^checkout/paypal/', include('paypal.express.urls')),
# Dashboard views for Payflow Pro
url(r'^dashboard/paypal/payflow/', include(payflow.urls)),
# Dashboard views for Express
url(r'^dashboard/paypal/express/', include(express_dashboard.urls)),
url(r'', include('apps.myapp_o.urls')),
)
Remember you do not have to import views from app while you're using string import.
Comment if this thing doesn't work.
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