I need to use Jython instead of Python, I found that jython2.7b2 works with DJango 1.7. So, I am stuck using the beta version. I am trying to follow the current Django tutorial and I have ran into a problem. I am not sure if I am using generic views properly. When I try to change the urls.py (polls) file. I see that pydev complains that views.IndexView, views.DetailView, and ResultsView don't exist. Am I doing something wrong? Or did they change the way generics work in version 1.7?
My System:
Windows 7
jython2.7b2
Django-1.7c3
postgresql-9.3.5-1-windows-x64
postgresql-9.3-1102.jdbc41.jar
Here is the url for the tutorial, go to the section "Use generic views: Less code is better"
Django tutorial part 04
Once you have changed your urls.py, you need to define the new views.
This is covered in the next section of the tutorials, Amend views.
Related
Today I decided to upgrade my project from Django 1.11 to 2.2.1. I've been working through various issues with my project, and I'm fighting through them. However, I spent most of tonight trying to get the URLs to work and they won't cooperate. Long story short, I have multiple app in my project and each app has a URL with it's own namespace. In Django 1.11 this is working fine. However, when I try to port the logic over to Django 2.2.1, I keep getting an error saying that I have a circular import somewhere probably.
Here is a snippit of what works just fine in Django 1.11.......
My Main Project...In Django 1.11
url(r'^Main/',include('AppA.urls',namespace="AppA")),
But when I try to do this in Django 2.2.1.....
I realize that URLs were replaced by paths...
path('', include('AppA.urls')),
But when I try to start my application it says....
your project does not appear to have any patterns in it. If you see valid p
atterns in the file then the issue is probably caused by a circular import.
I can't seem to figure out how to create the namespace that is working in django 1.11 so that I can properly reference my urls in my templates.
I've been staring at this most of the evening and that might be why I'm not seeing it...I also looked at the Django doc...https://docs.djangoproject.com/en/2.2/topics/http/urls/
And I just can't see what I might be doing wrong. Thanks in advance for any help to get me back on track.
As Bloodmallet pointed out to me...
I needed to add....
app_name = 'Appa'
to the top of my urls.py file. After doing this, the path URL worked as expected.
Instead of path(), consider using re_path():
from django.urls import include, re_path
re_path(r'^Main/',include('AppA.urls',namespace="AppA")),
I have been using
the braces LoginRequired Mixin in the past, Now it does not seem to work. No errors just you can see the view without Logging in.
Is this the same library?
It seems that a lot of things have changed in django since the last time I have used it. thanks.
You can use official django login_required method.
from django.contrib.auth.decorators import login_required
class SomeClassView(View):
#classmethod
def as_view(cls, **initkwargs):
view = super(SomeClassView, cls).as_view(**initkwargs)
return login_required(view)
Documentation: https://docs.djangoproject.com/en/1.8/topics/auth/default/#the-login-required-decorator
Yes, this is the same library. The ReadTheDocs link that you posted links directly to the brack3t/django-braces page linked in your question.
Regarding versioning, here is the statement from the Readme.md file:
Our policy going forward is that django-braces officially supports the current version of Django and one version each direction (e.g. 1.6.x is current, so 1.5.x, 1.6.x, and 1.7.x are all supported). There won't be any restraints on using other versions of Django, though, but it will be a "buyer beware" situation.
According to the repo's releases page, v1.8 is current, so it should support Django 1.7.x, 1.8.x, and 1.9.x under the current release.
I am in the process of upgrading huge project from Django 1.6.2 towards latest 1.8 version.
Following all release notes here: https://docs.djangoproject.com/en/1.8/releases/1.7/#using-a-custom-manager-when-traversing-reverse-relations
I believe I revisited my entire project for backwards incompatibilities, but I am still getting this error on any reverse url call to any admin page.
from django.core.urlresolvers import reverse
reverse('admin:scanners_scanner_changelist')
NoReverseMatch: Reverse for 'scanners_scanner_changelist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
This was working just fine on django 1.6.x
It's very frustrating as this error tells you nothing... Basically you have to guess and try what's wrong. Do any of you guys have some ideas what I might be missing, what is changed from Django 1.6 to 1.7 that could potentially cause this?
All other urls work fine except for admin changelist and change urls.
Finally figured this out. django-adminplus was a cause of this.
So if you are having similar problems when upgrading from Django 1.6.x to 1.7.x try to change django.contrib.admin to django.contrib.admin.apps.SimpleAdminConfig and do not remove admin.autodiscover() from your main urls.py file. This way you are doing admin discovery manually and explicitly, the old way instead of new implicit method which might cause you troubles if you are doing some serious hacking within your project.
Cheers!
We are considering migrating our dated django 1.3.1 app to the latest version (1.5.4).
I don't like migrations.
Are any specific problems to be thought of? Any show stoppers you may think of?
Of course I will study release notes and all this.
Will it be a real head ache or is it doable?
We have migrated our app from 1.4 to 1.5, we didn't fetch any issue which is blocker. We had needed to done couple of changes related to adminmedia, json library uses and url syntaxing in our html templates. They were some normal issues only.
But yes as you said its always better to check release notes before upgrading to latest version.
Hope this will help you.
Here are the few things you need to take care of:
Project directory structure has been changed.
Include ALLOWED_HOSTS in settings.py.
django.utils.simplejson is deprecated. import simplejson can be used instead.
Session data will not be saved, when the response code is 500.
django.forms.ModelMultipleChoiceField now returns an empty QuerySet as the empty value instead of an empty list.
Uploaded files are no longer created as executable by default. If you need them to be executable change FILE_UPLOAD_PERMISSIONS to your needs.
{% load adminmedia %} template tag can no longer be used.
If you’re using django.contrib.redirects, make sure INSTALLED_APPS contains django.contrib.sites.
I keep hitting an error when trying to use django-debug-toolbar and django-cms together.
"MpttMeta has no attribute 'class'"
I have a feeling it's something to do with the Mptt app bundled with Django CMS, but I'm not sure, and I've seen this on a few projects but I'm surprised I can't find a direct hit for the error message in Google so I thought I'd post here.
I've tried using latest released version of debug toolbar, also the develop branch, and also dcramer's fork, but it's making no difference. I'm on Django 1.3 and Django CMS 2.1.3.
Any ideas?
Thanks!
The problem is that django-debug-toolbar expects the MpttMeta class needs to be a 'new style' class, which is a fairly straightforward patch (line 33 in django-cms/publisher/mptt_support.py). Change:
class MpttMeta:
to
class MpttMeta(object):
In Django-CMS 2.1.3, they still have their own monkey-patched mptt bundled with Django-CMS. In the next release of Django-CMS will no longer bundle its own mptt and will instead rely on the independently developed package.
It could be any problem related to Django 1.3.
Django CMS 2.1.3 supports only 1.2.X branch: http://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements
Jonas Obrist, Django CMS dev says "Maybe a minor version of
2.1 will add official 1.3 support"
Or you can put this in yours .... urls.py for example. Not in settings.py because project will not start.
from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
MpttMeta.__class__ = type
Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'
I believe this had to do with the way the MPTTMeta class is loaded into the metaclass (MPTTModelBase) making it not have a class attribute.
A monkeypatch fix is to wrap the offending statement in django-debug-toolbar like so:
try:
text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)
This changes the output slightly to become
method finish_mptt_class on classobj object
Clearly not a permanent fix, but it gets you the debug-toolbar + django-cms working.