ImportError:没有名为myapp_o.url的模块。

时间:2021-01-29 20:26:33

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.

我正在做一个django-oscar项目。我一直在到处寻找解决这个问题的方法。虽然我在这里遇到过类似的问题,但我仍然无法解决这个问题。

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.

我正在尝试创建其他页面,比如“about”和“contacts”。我检查了仪表板,寻找页面创建,但似乎无法实现我想要的功能。我想把这些页放在页脚区域。我可以将这些在仪表板上创建的页面显示到我的页脚,但是仅仅显示文本看起来很简单。我想知道我是否能做得更多。

I have created an app in my apps folder. Here is the folder structure:

我在apps文件夹中创建了一个app。以下是文件夹结构:

ImportError:没有名为myapp_o.url的模块。

ImportError:没有名为myapp_o.url的模块。

Here is my env installs -

这是我的env安装-

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

这是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

这是应用程序。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

这里是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.

谢谢你!

1 个解决方案

#1


0  

Let's check your code first:

让我们先检查一下您的代码:

on apps/myapp/urls.py, you should NOT import like this.

在应用程序/ myapp / url。py,不应该像这样导入。

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).

其次,在Django 1.8之后,urlpatterns不再使用模式。您应该考虑在Django1.10之后使用url函数来使用代码(不赞成使用1.10模式之后)。

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.

我还添加$ end of your url,以完全匹配用户请求的url。

Third, when I searched django docs with i18n_patterns,

第三,当我使用i18n_patterns搜索django文档时,

You can use django's urls with String include like include('paypal.express.urls').

您可以使用django的url,其中包含的字符串包括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.

记住,在使用字符串导入时,不需要从应用程序中导入视图。如果这个东西不管用,请评论。

#1


0  

Let's check your code first:

让我们先检查一下您的代码:

on apps/myapp/urls.py, you should NOT import like this.

在应用程序/ myapp / url。py,不应该像这样导入。

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).

其次,在Django 1.8之后,urlpatterns不再使用模式。您应该考虑在Django1.10之后使用url函数来使用代码(不赞成使用1.10模式之后)。

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.

我还添加$ end of your url,以完全匹配用户请求的url。

Third, when I searched django docs with i18n_patterns,

第三,当我使用i18n_patterns搜索django文档时,

You can use django's urls with String include like include('paypal.express.urls').

您可以使用django的url,其中包含的字符串包括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.

记住,在使用字符串导入时,不需要从应用程序中导入视图。如果这个东西不管用,请评论。