cannot import name 're_path' I am using django version 2.0.6 - django

I want to use re_path from django.urls, django doc says I can use this from django version 2,
From the error I came to know that I am using django version 2.0.6.
But I am not able to re_path
ImportError at /
cannot import name 're_path'
Request Method: GET Request URL: http://djangosite.com/ Django Version:
2.0.6 Exception Type: ImportError Exception Value:
cannot import name 're_path'
Exception Location: /home/sugushiva/myproject/filope/blogs/urls.py in
, line 1 Python Executable: /usr/bin/python3
In main urls.py
from django.contrib import admin
from django.urls import path, re_path,include
urlpatterns= [
path('admin/',admin.site.urls),
re_path('^$', include('blogs.urls'))
]
in blogs.urls
from django.db import re_path
from .models import blogindex
urlpatterns = [
re_path('^$',blogindex)
]

You are importing the wrong path in blogs/urls.py.
from django.db import re_path
Should instead be:
from django.urls import re_path

Related

NoReverseMatch " " is not a registered namespace

Hello guys I've been struggling to move my project in another location in anaconda so after finally installing everything and setting up the project I am getting some errors that I don't understand. First of all I had my code on a sub-folder inside my app called api there I had my views, serializers, urls. And I included the urls but nothing seemed to happen. I moved all the api files to the app folder and I deleted the api folder. Now I'm getting this error NoReverseMatch at /op_data/objects/ ('api-op-data' is not a registered namespace). Even after deleting this url I keep getting the same error. This is my code:
urls.py
from django.urls import path, re_path
from django.views.generic import TemplateView
from django.conf.urls import url, include
from django.contrib import admin
from djgeojson import views
from djgeojson.views import GeoJSONLayerView
from django.conf.urls.static import static
import MMA
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from MMA import views
from rest_framework_jwt import views
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token, verify_jwt_token
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/auth/token/$', obtain_jwt_token, name='api-auth-token'),
url(r'^api/', include(('MMA.urls', 'api-op-data'), namespace='api-op-data')),
]
urls.py
from django.conf.urls import url
from django.contrib import admin
from .views import OP_Data_RudView, OP_Data_ApiView, UserCreateAPIView, UserLoginAPIView, WoType_ApiView, WoType_RudView, UserObjects_ApiView, UserObjects_RudView
app_name = 'MMA'
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^users/register/$', UserCreateAPIView.as_view(), name='register'),
url(r'^users/login/$', UserLoginAPIView.as_view(), name='login'),
url(r'^op_data/$', OP_Data_ApiView.as_view(), name='post-listcreate'),
url(r'^op_data/(?P<pk>\d+)/$', OP_Data_RudView.as_view(), name='post-rud'),
url(r'^op_data/wo_type/$', WoType_ApiView.as_view(), name='post-listcreate'),
url(r'^op_data/wo_type/(?P<pk>\d+)/$', WoType_RudView.as_view(), name='post-rud'),
url(r'^op_data/objects/$', UserObjects_ApiView.as_view(), name='post-listcreate'),
url(r'^op_data/objects/(?P<pk>\d+)/$', UserObjects_RudView.as_view(), name='post-rud'),
]
error log:
NoReverseMatch at /op_data/objects/
'api-op-data' is not a registered namespace
Request Method: GET
Request URL: http://---.--.-.---:7000/op_data/objects/
Django Version: 2.0.6
Exception Type: NoReverseMatch
Exception Value:
'api-op-data' is not a registered namespace
Exception Location: C:\Users\Administrator.HR-JUGOR\Anaconda3\envs\MMA\lib\site-packages\django\urls\base.py in reverse, line 86
Python Executable: C:\Users\Administrator.HR-JUGOR\Anaconda3\envs\MMA\python.exe
Python Version: 3.6.5
Python Path:
['C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\Mobile',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\python36.zip',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\DLLs',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\win32',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\Pythonwin']
Server time: Wed, 24 Jul 2019 09:49:27 +0000
/op_data/objects/ isn't the configured url for post-listcreate, its api/op_data/objects/.
In this case the namespace argument seems to be redundant, you already declared the namespace as '^api/' before the include(), declaring it explicitly as 'api-op-data' later the same line seems unnecessary based on the code provided, though I would need to see how you were accessing these urls from your views and templates to know for sure.
You also don't need to redeclare your admin url in MMA.urls, and I question your decision to include the api/auth/token url in the root url config, it seems like it belongs in MMA.urls with the other urls in the api namespace

ModuleNotFoundError: No module named 'django.urls' not working in Django 1.9

I'm using Django 1.9
from django.contrib admin
from django.conf.urls import include, url
from slack.views import DRSWebhookTransactionView, DRSMessageView
from django.urls import path
api_patterns = ([
path('web/', DRSWebhookTransactionView.as_view()),
path('events/', DRSMessageView.as_view()),
], 'api')
urlpatterns = [
url(r'^admin/', admin.site.urls),
path('api/v1/', include(api_patterns)),
]
After running python manage.py runserver:
from django.urls import ( # noqa
ModuleNotFoundError: No module named 'django.urls'
I'm getting this error after I tried including path. If I don't include path it's not showing the error for the 'path', it's still showing the same error. Can someone tell how can I rewrite this program? and tell me what I'm doing wrong?
for django 1.9
from django.conf.urls import url
refer this

ImportError: cannot import name views while running the server

I am getting following error and donĀ“t know how to solve this:
from . import views
ImportError: cannot import name views
This are my scripts i am using:
urls.py
from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^$',views.home,name='index'),
url(r'^admin/', admin.site.urls),]
views.py
from __future__ import unicode_literals
from django.http import HttpResponse
def index(request):
return HttpResponse("libaray management system")
Try to import like this
from your_app_name import views
I can't say, what is your project structure and where are your views.py and urls.py files. My guess, that you have some problems with how you import (check the absolute and relative import in python). In that case you can use import style from above code example.

django rest framework "ModuleNotFoundError: No module named 'router'"

i have imported all the restframework packages but i don't understand why am i getting this strange error
from django.conf.urls import *
from django.contrib import admin
from django.views.generic.base import TemplateView
from .views import Create,Home,signup,Search,QuestionViewSet
from django.urls import reverse
from .models import Question
from django.contrib.auth import views as auth_views
from rest_framework import routers
router=routers.DefaultRouter()
router.register(prefix='question1',viewset=QuestionViewSet)
app_name='main'
urlpatterns = [
# url(r'^/',views.home,name='home'),
url(r'^home/',Home,name='home'),
url(r'^ques/',Create.as_view(success_url="/index/home/"),name='ques'),
url(r'^signup/',signup,name='signup'),
url(r'^logout/$', auth_views.logout,name='logout'),
url(r'^search/',Search,name='search'),
url(r'^api/', include('router.urls'))
# CreateView.as_view(model=myModel, success_url=reverse('success-url'))
]
this is the issue i'm facing
ModuleNotFoundError: No module named 'router'
any kind of help is appreciated
thanks in advance
First argument of include method can be module name or pattern list. Since router.urls is patterns list it should be
url(r'^api/', include(router.urls))
instead of
url(r'^api/', include('router.urls'))
So you need to remove '' signs.

Import Error : cannot import register

Getting Import error while trying to run localhost from my urls.py:
from django.conf.urls.defaults import *
from django.conf import settings
from django.http import HttpResponseRedirect
from django.contrib import admin
from mainapp.feeds import LatestReports, CityIdFeed, CitySlugFeed, WardIdFeed, WardSlugFeed,LatestUpdatesByReport
from mainapp.models import City
from social_auth.views import auth as social_auth
from social_auth.views import disconnect as social_disconnect
#Error at this line
from registration.views import register
from mainapp.forms import FMSNewRegistrationForm,FMSAuthenticationForm
from mainapp.views.account import SUPPORTED_SOCIAL_PROVIDERS
from django.contrib.auth import views as auth_views
from mainapp.views.mobile import open311v2
import mainapp.views.cities as cities
Traceback:
ImportError at /
cannot import name register
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3
Exception Type: ImportError
Exception Value:
cannot import name register
Exception Location: /home/sourabh/Django/fixmystreet/fixmystreet/../fixmystreet/urls.py in <module>, line 9
Python Executable: /home/sourabh/Django/fixmystreet/bin/python
Python Version: 2.7.3
Python Path:
['/home/sourabh/Django/fixmystreet/fixmystreet',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7',
'/home/sourabh/Django/fixmystreet/lib/python2.7/plat-linux2',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-tk',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-old',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/PIL',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/PIL']
Server time: Thu, 22 Aug 2013 09:34:40 -0500
If you look at the docs you see that register is something that used to exist and was deprecated in the last version. From the documentation:
The 1.0 release of django-registration represents a complete rewrite
of the previous codebase, and introduces several new features which
[...]
You either downgrade to django-registration v0.8 (where registration.views.register still exists) or learn how to implement the changes to fit the newest version