Django conflict between older example code and new version - django

My first post here. I have started learning Django over the past week. I have experience with other languages such but am also fairly new to python.
I have been going through this book: http://withdjango.com It has been great so far, however it was written when Django was at version 1.0 if I can tell correctly. However I am using Django 1.6.
I have managed to figure out a few of the small differences between the two here and there, however I am stuck on this one.
I have attempted to follow along with there 'pastebin' exercise (all of the source code is here http://withdjango.com.s3.amazonaws.com/src/pastebin.zip)
One thing I noticed was they used:
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import create_object
Where as in 1.6, if I am correct it should be
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
However when I launch this set of code which I have written. I get the following error:
> TypeError at /
> __init__() takes exactly 1 argument (4 given) Request Method: GET Request URL: http://[REMOVED FOR SECURITY] Django
> Version: 1.6.1 Exception Type: TypeError Exception Value:
> __init__() takes exactly 1 argument (4 given) Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py
> in get_response, line 114 Python Executable: /usr/bin/python Python
> Version: 2.7.3 Python Path: ['/home/phil/pastebin',
> '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2',
> '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
> '/usr/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7']
> Server time: Tue, 21 Jan 2014 03:25:26 +0000
Does anyone have any idea? I should also mention that I have tried using the exact source code the provide online, only changing those changes I mentioned.
Sorry if this is obvious, but I am brand new to all of this. Thank you for any help!

Django 1.0 and latest stable 1.6 have great differences. I advise learning through a more updated book. Particularly Django's own tutorial or Two Scoops of Django have great material (the latter book is going to be updated for 1.6 in near future).

Related

cannot import name 'url' from 'django.conf.urls' (/app/.heroku/python/lib/python3.9/site-packages/django/conf/urls/__init__.py)

ImportError at /
cannot import name 'url' from 'django.conf.urls' (/app/.heroku/python/lib/python3.9/site-packages/django/conf/urls/__init__.py)
Request Method: GET
Request URL: https://aas-system.herokuapp.com/
Django Version: 4.0.1
Exception Type: ImportError
Exception Value:
cannot import name 'url' from 'django.conf.urls' (/app/.heroku/python/lib/python3.9/site-packages/django/conf/urls/__init__.py)
Exception Location: /app/.heroku/python/lib/python3.9/site-packages/webpush/urls.py, line 1, in <module>
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.9.10
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python39.zip',
'/app/.heroku/python/lib/python3.9',
'/app/.heroku/python/lib/python3.9/lib-dynload',
'/app/.heroku/python/lib/python3.9/site-packages'
]
Server time: Tue, 01 Feb 2022 07:52:34 +0000
If you are using Django 4.0 and higher then django.conf.urls.url() is removed.
You can use re_path[Django-doc] in case of url, which also use regex as url.
from django.urls import path, re_path
urlpatterns = [
re_path(r'^$', views.your_view_name),
]
It looks like you are using Django 4. In this version, url from django.conf.url no longer works.
https://docs.djangoproject.com/en/3.2/ref/urls/#url
So you have two options.
Use something below Django 3.2. I suspect that what you are doing on your local version. FYI, using pip freeze > requirements.txt in your local environment is a good way to save your configuration and it can simplify the installation in other env.
Or update your code. You should then try re_pathin order to do so
https://docs.djangoproject.com/en/4.0/ref/urls/#re-path

django throwing ImproperlyConfigured error while importing data using 'django-import-export' library

I'm trying to import data into a model through django admin using dajngo-import-export library, though I'm facing "Improperly Configured" error.
This is the error message:
ImproperlyConfigured at /admin/pages/quote/import/
No exception message supplied
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/pages/quote/import/
Django Version: 3.0
Exception Type: ImproperlyConfigured
Exception Location: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\lib\site-packages\import_export\resources.py in import_data, line 737
Python Executable: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Users\\Dell\\Downloads\\read_bus',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts\\python37.zip',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\DLLs',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts',
'c:\\users\\dell\\anaconda3\\Lib',
'c:\\users\\dell\\anaconda3\\DLLs',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages',
'C:\\Users\\Dell\\Downloads\\read_bus',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',]
I'm following the documentation as mentioned here.
This is the admin.py file:
class QuoteResource(resources.ModelResource):
class Meta:
model =Quote
import_id_fields=('quote',)
fields = ('quote','book','author',)
class QuoteAdmin(ImportExportModelAdmin):
list_display=('quote','book','author')
resource_class =QuoteResource
admin.site.register(Quote,QuoteAdmin)
I've tried with and without 'QuoteResource', without success.
I'm successfully able to export the data from admin. But facing challenge during import. Snip of admin during import:
Following is one of the various ways in which I tried to import data:
Does it has somthing to do with the django settings or the csv data format?
Let me if you need any more information.
Your error comes from import export trying to use database transactions but transactions not being supported. So this is an issue with your database.
The section of code from django-import-export can be seen here: https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L737
To disable transactions, add the setting & make it false; IMPORT_EXPORT_USE_TRANSACTIONS.
You can see that here; https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L44

i have two projects in django i can not open admin site for my second project,but i can open for my first project,can any one help me

AttributeError at /admin/
'WSGIRequest' object has no attribute 'user'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 2.0.2
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'user'
Exception Location: C:\Users\vaaz\Desktop\venv\lib\site-packages\django\contrib\admin\sites.py in has_permission, line 186
Python Executable: C:\Users\vaaz\Desktop\venv\Scripts\python.exe
Python Version: 3.4.3
Python Path:
['C:\Users\vaaz\website1',
'C:\Windows\system32\python34.zip',
'C:\Users\vaaz\Desktop\venv\DLLs',
'C:\Users\vaaz\Desktop\venv\lib',
'C:\Users\vaaz\Desktop\venv\Scripts',
'C:\Python34\Lib',
'C:\Python34\DLLs',
'C:\Users\vaaz\Desktop\venv',
'C:\Users\vaaz\Desktop\venv\lib\site-packages']
Server time: Mon, 12 Mar 2018 10:21:49 +0000
This looks similar to this post
with your limited error description I can only suggest a few things that were mentioned in the above post:
Older Django versions use MIDDLEWARE_CLASSES = (...) in the settings.py rather than MIDDLEWARE = (...) try changing that variable.
If you are using virtualenv be sure to activate it before trying to runserver
If you created your app in a different version of Django and then installed it on another version it might give you errors.

django cms frontend editer display error

Am trying to access the django cmcs frontend editor and after input the login details, i get the following error.
AttributeError at /en/
'NoneType' object has no attribute 'has_change_permission'
Request Method: GET
Request URL: http://*.*.*.*:8000/en/
Django Version: 1.6.5
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'has_change_permission'
Exception Location: /home/bg/workspace/my-site/env/local/lib/python2.7/site-packages/cms/templatetags/cms_tags.py in get_processors, line 352
Python Executable: /home/bg/workspace/my-site/env/bin/python
Python Version: 2.7.3
Python Path:
['/home/bg/workspace/my-site',
'/home/bg/workspace/my-site/env/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/bg/workspace/my-site/env/lib/python2.7',
'/home/bg/workspace/my-site/env/lib/python2.7/plat-linux2',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-tk',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-old',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/bg/workspace/my-site/env/local/lib/python2.7/site-packages']
How can i fix it?
I faced a similar issue with django-cms 3.0.4 / Python 3.4, it may be related to the djangocms-column plugin (version 1.4).
This problem appeared when editing a page; either with djangocms-installer default pages, as well as when creating a new page at trying to add the multi-columns plugin into it.
For a bit more details, the error is encountered when interpreting {% render_plugin plugin %}, in multi_column.html (line #4):
In template /dvlpt/venv/my_project/lib/python3.4/site-packages/djangocms_column/templates/cms/plugins/multi_column.html, error at line 4
'NoneType' object has no attribute 'has_change_permission'
More exactly, the AttributeError exception is raised by line #352 of cms/templatetags/cms_tags.py, in get_processors():
if toolbar and toolbar.edit_mode and placeholder.has_change_permission(request) and getattr(placeholder, 'is_editable', True):
...
I've posted a comment at djangocms-colum github : https://github.com/divio/djangocms-column/issues/14
Sorry, I cannot bring a more useful help yet, as I'm very new to django-cms at this time...
Cheers

Django ViewDoesNotExist error after installing photologue

I'm using Django 1.5.1. Everything was OK. But as soon as I installed django-photologue through pip I face this error when I visit admin url:
> **ViewDoesNotExist at /admin/**
Could not import django.views.generic.list_detail.object_list. Parent module django.views.generic.list_detail does not exist.
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.5.1
Exception Type: ViewDoesNotExist
Exception Value:
Could not import django.views.generic.list_detail.object_list. Parent module django.views.generic.list_detail does not exist.
Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in get_callable, line 104
Python Executable: /usr/bin/python
Python Version: 2.7.3
Also when I run syncdb, photologue sync with database without any error and I can import it in shell.
Any idea about how can I solve this error?
to replace the file in the directory urls.py photologue :
"django.views.generic.date_based" and "django.views.generic.list_detail" on "django.views.generic"
"object_list" on "list.ListView"
"object_detail" on "detail.DetailView"
"archive_year" on "dates.YearArchiveView"
"archive_month" on "dates.MonthArchiveView"
"archive_day" on "dates.DayArchiveView"
like this :)
or read :
django-photologue was most likely built for an older version of Django. Looks like the newer version of Django isn't friendly with generic views and prefers class based views instead.
Downloading a fresh copy of Django 1.5.1 shows the following:
http://f.cl.ly/items/0k1J261S2J2f3k3C110I/Image%202013.04.20%203%3A44%3A39%20AM.png
Whereas Django 1.4.2 shows:
http://f.cl.ly/items/152J2U050X0z1j1n0v0D/Image%202013.04.20%203%3A46%3A49%20AM.png
Simply put, the newer version of Django removed the list_detail file.