Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urls.py , views.py need some changes to support Django > 3.2 #14

Closed
chayapan opened this issue Sep 14, 2023 · 1 comment
Closed

urls.py , views.py need some changes to support Django > 3.2 #14

chayapan opened this issue Sep 14, 2023 · 1 comment

Comments

@chayapan
Copy link

chayapan commented Sep 14, 2023

I'm getting this error when trying to add django-ide to a project.

  • django [required: >=3.2, installed: 4.1.7]
  • django-ide==0.0.5
.../lib/python3.10/site-packages/djide/urls.py", line 1, in <module>
    from django.conf.urls.defaults import patterns, include, url
ModuleNotFoundError: No module named 'django.conf.urls.defaults'

This is probably a simple fix per this thread:
https://stackoverflow.com/questions/19962736/django-import-error-no-module-named-django-conf-urls-defaults

django.conf.urls.defaults has been removed in Django 1.6. If the problem was in your own code, you would fix it by changing the import to

from django.conf.urls import url, include
@chayapan
Copy link
Author

chayapan commented Sep 14, 2023

It seems 9e4cdea already made the change.

However that solution didn't work in my case. So I try this: Tivix/django-rest-auth#659

Then had another issue with djide/views.py which is addressed by:
https://stackoverflow.com/questions/7775062/porting-python-2-program-to-python-3-random-line-generator

def setMetaFile(app_name, metaData):
    IDE_PATH = os.path.dirname(os.path.abspath(__file__))
    metaDataFile = os.path.join(IDE_PATH,'metafiles/.%s' % urllib.unquote_plus(app_name))
    try:
        handle = open(metaDataFile, 'w')
        handle.write(metaData)
    except IOError as err:
        errno, strerror = err.args
        return HttpResponse('File exception (%s): %s, %s'%(metaDataFile,errno,strerror))
    finally:
        handle.close()

Then

ModuleNotFoundError: No module named 'urllib2'

Then

ImportError: cannot import name 'render_to_response' from 'django.shortcuts'

https://stackoverflow.com/questions/55911435/django-importerror-cannot-import-name-render-to-response-from-django-shortcu

from django.shortcuts import render     
...
        return render(request, 'ide.html', {'app_name':app_name})
...
        return render(request, 'index.html', {'apps':list(set(a))})
NameError: name 'patterns' is not defined
urlpatterns = [   
    url(r'^$', djide.views.edit, name='edit'),
    url(r'^tree-data$', djide.views.tree_data, name='treedata'),
    url(r'^model-editor', djide.views.model_editor, name='modeleditor'),
]

Then when editing a file:

    return open(os.path.join(rootPath, urllib.unquote_plus(id))).read()
NameError: name 'urllib' is not defined
  • unquote_plus needs to be imported from urllib.parse.
from urllib.parse import unquote_plus, quote_plus
...
# change urllib.unquote_plus to unquote_plus

Then when saving changes:

    setMetaFile(request.POST.get('app_name'),request.POST.get('meta').decode('string_escape'))
AttributeError: 'str' object has no attribute 'decode'

https://stackoverflow.com/questions/28583565/str-object-has-no-attribute-decode-python-3-error

request.POST.get('meta').decode('string_escape'))
to
request.POST.get('meta')

Then

...line 66, in model_editor
    for (fileName,fileContent) in dataArray.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

https://stackoverflow.com/questions/30418481/error-dict-object-has-no-attribute-iteritems

change .iteritems() to .items()

@chayapan chayapan changed the title urls.py needs change to support Django > 1.6 urls.py , views.py need some changes to support Django > 3.2 Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant