lemaiyan / mpesa_api

Mpesa B2C, C2B, STKPush Django framework based on the new Api's https://developer.safaricom.co.ke
MIT License
73 stars 70 forks source link

Url include misbehaving in django 2.0 #4

Closed lemaiyan closed 5 years ago

lemaiyan commented 6 years ago

When running the app on Django 2 it throws the error below

File "/usr/src/app/config/urls.py", line 21, in <module>
    url(r'^mpesa/', include('mpesa_api.core.urls', 'mpesa')),
  File "/usr/local/lib/python3.6/site-packages/django/urls/conf.py", line 39, in include
    'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
otuoma commented 6 years ago

Updating \mpesa-api\mpesa_api\core\urls.py by adding app_name = 'mpesa' will likely resolve the issue

app_name = 'mpesa'

urlpatterns = [ url('^b2c/timeout$', B2cTimeOut.as_view(), name='b2c_timeout'), url('^b2c/result', B2cResult.as_view(), name='b2c_result'), url('^c2b/confirmation', C2bConfirmation.as_view(), name='c2b_confirmation'), url('^c2b/validate', C2bValidation.as_view(), name='c2b_validation'), url('^c2b/online_checkout/callback', OnlineCheckoutCallback.as_view(), name='c2b_checkout_callback'), ]

Further, URL patterns in > django 2.0 moved from regular expressions. Rewriting the URL patterns will probably work better going forwards?

path('mpesa/', include('mpesa_api.core.urls', namespace='mpesa'))

https://docs.djangoproject.com/en/2.0/topics/http/urls/#example

lemaiyan commented 5 years ago

Thanks for this @otuoma. 👍