Django Admin Interface - Privileges On Development Server - python

I have an old project running (Django 1.6.5, Python 2.7) live for several years. I have to make some changes and have set up a working development environment with all the right django and python requirements (packages, versions, etc.)
Everything is running fine, except when I am trying to make changes inside the admin panel. I can log on fine and looking at the database (sqlite3) I see my user has superuser privileges. However django says "You have no permissions to change anything" and thus not even displaying any of the models registered for the admin interface.
I am using the same database that is running on the live server. There I have no issues at all (Live server also running in development mode with DEBUG=True has no issues) -> I can only see the history (My Change Log) - Nothing else
I have also created a new superuser - but same problem here.
I'd appreciate any pointers (Maybe how to debug this?)

Finally, I found the issue:
admin.autodiscover()
was commented out in the project's urls.py for some reason. (I may have done that trying to get the project to work in a more recent version of django) - So admin.site.register was never called and the app_dict never filled. index.html template of django.contrib.admin then returns
You don't have permission to edit anything.
or it's equivalent translation (which I find confusing, given that the permissions are correct, only no models were added to the admin dictionary.
I hope this may help anyone running into a similar problem

Related

Django admin panel lags and doesn't show anything

Today I've launched my Django project and saw a really weird behavior of Django admin panel. At the first sight, everything looks OK but as soon as I click on any model to view, I can't see anything. The most strange thing is that I've got no weird commits that could damage the contents of admin panel recently. The only commit could do that is updating Django to 3.1 version. I've already tried reinstalling Django and installing older versions but nothing works.
Here is the typical admin panel homepage
Here is what happens when I click on models
I really need to know how to fix it as well as both me and my friend have this issue and we can't deal with it.
First thing that you should check for this error is to see if you are calling:
admin.site.register(<model-name>)
and not
admin.register(<model-name>)
if this is not the case then try running the migrations again
python manage.py makemigrations
python manage.py migrate
Finally, make sure your admin.py file with the code is actually inside the directory of the app (i.e. the same directory with your models.py that defines MyModel).

Strange error during initial database migration of a Django site

I have been working on a localhost copy of my Django website for a little while now, but finally decided it was time to upload it to PythonAnywhere. The site works perfectly on my localhost, but I am getting strange errors when I do the initial migrations for the new site. For example, I get this:
mysql.connector.errors.DatabaseError: 1264: Out of range value for
column 'applied' at row 1
'applied' is not a field in my model, so this error has to be generated by Django making tables for its own use. I have just checked in the MySQL manager for my localhost and the field 'applied' appears to be from the table django_migrations.
Why is Django mishandling setting up tables for its own use? I have dropped and remade the database a number of times, but the errors persist. If anyone has any idea what would cause this I would appreciate your advice very much.
My website front end is still showing the Hello World page and the Admin link comes up with a page does not exist error. At this stage I am going to assume this is related to the database errors.
EDIT: Additional information about why I cannot access the front-end of the site:
It turns out when I am importing a pre-built site into PythonAnywhere, I have to edit my wsgi.py file to point to the application. The trouble now is that I don't know exactly what to put there. When I follow the standard instructions in the PythonAnywhere help files nothing seems to change. There website is also seems to be very short on detailed error messages to help sort it out. Is there perhaps a way to turn off their standard hello world placeholder pages and see server error messages instead?
As it says in my comment above, it turns out that the problem with the database resulted from running an upgrade of Django from 1.8 to 1.9. I had forgotten about this. After rolling my website back to Django 1.8, the database migrations ran correctly.
The reason why I could not access the website turned out to be because I had to edit the wsgi.py file, but I was editing the wrong version. The nginx localhost web server I was using keeps it in the different folder location than PythonAnyhwere's implementation. I uploaded the file from my localhost copy and edited it according to the instructions on PythonAnywhere's help system without realizing it was not being read by PythonAnywhere's server. What I really needed to do was edit the correct file by accessing it through the web tab on their control panel. Once I edited this file, the website front end began to work as expected.
This issue occurred for me as well on version 1.10 with a brand new project. I found that if you use the recommended driver and the connector in the documentation, the migration works without issues.
If you don't feel like reading the docs, in breif:
Install MySQLdb for python 2.7 or mysqlclient for python 3.3+
Modify your settings.py file. In the DATABASES dictionary set:
'ENGINE': 'django.db.backends.mysql',

Django plugged into Apache not working like Django standalone

I have encountered a hodgepodge of errors trying to bring my django site into production with Apache. Having finally gotten mod_wsgi sorted and Apache at least seeming to be trying to load the site I'm seeing a number of confusing problems in the debug details when the homepage fails to load.
None of these errors emerge when I fire up the site using python manage.py runserver 10.10.10.214:8080 - it works 100% fine that way
Import errors - I cannot from x import y - for some reason it will only allow me to do from x import * An example was #from django.conf.urls import patterns, include, url gave an error - I had to change to from django.conf.urls.defaults import *
Permission errors - for example, I had to chmod the DB file which worked fine before. No big deal I suppose but I just wondered why
DB field errors: Cannot resolve keyword 'user_id' into field. Choices are: end_date, id, singleDate, start_date, user user_id worked just fine in standalone mode.
Apache log was giving errors like TemplateSyntaxError: Caught ImportError while rendering: No module named staticfiles which I just lazily bypassed by commenting out django.contrib.staticfiles in settings.py. This solved nothing, needless to say
It almost felt like the files were being handled on a standalone basis and not within the django framework. Has anyone experienced these kind of teething problems before? I was foolishly thinking I could just plug in. I have a (unfounded) optimistic feeling it must just be a directive in some file.
Cheers, Arthur
Are you sure the target system has the same version of Django installed?
Is the mod_wsgi even compiled for the version of Python you want to use? It is a common mistake that people don't realise that mod_wsgi is actually for a different Python version and so not using the same Python installation as you expect and therefore using different versions of packages.
As to the permissions errors, this is because the code when run under Apache is running as the Apache user by default. It will not have access rights the same as you do when run manually. You also have to be careful on making assumptions about what the working directory of the process is.
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Working_Directory
In order to try and sort out things out, you may be better to try and use mod_wsgi-express in your development environment. This way development environment is closer to your target system.
http://blog.dscpl.com.au/2015/04/integrating-modwsgi-express-as-django.html
http://blog.dscpl.com.au/2015/04/using-modwsgi-express-with-django.html
http://blog.dscpl.com.au/2015/05/using-modwsgi-express-as-development.html

How to start a django app

I'm trying to use django-ios-notifications to server PUSH notifications via APNS (https://github.com/stephenmuss/django-ios-notifications). I've never used Django before. I've followed the instructions on the modules github page, but have'nt been able to get it working. I've done the following;
*installed required package and django
*added 'ios_notifications', to my INSTALLED_APPS settings file
*synced my local MySQL server with django (a load of new tables were created, for both django and django-ios-notifications, so it appears to be installed correctly, which I was thrilled about)
*start django server
However when I go to the modules config page (URL below) I just see the default 'It worked!
Congratulations on your first Django-powered page.' holding page, not the admin page I expected. (the tutorial on the github page descried a form)
http://127.0.0.1:8000/admin/ios_notifications/apnservice/add/
I guess I need to configure something in djange, I read over the first few pages on the django tutorial but I couldn't see any mention of using installed modules. I'm sure this is a very simple problem to solve, so if anyone could point me in the right direction that would be fantastic.
https://github.com/stephenmuss/django-ios-notifications
You don't seem to have activated Django's admin interface, which you need to access the admin forms. There are concise instructions in the documentation. You can switch to a different version of Django in the lower right corner, if you aren't using 1.5.

djangoappengine User Creation and Data Persistence is Broken

I recently updated to appengine SDK 1.6 and I'm having trouble with persisting data on my dev environment. I have everything setup according to the official installation guide.
Even though I had a super user account setup for my app previously, it no longer works. I created the account again with
manage.py createsuperuser
and it seems to do what it's supposed to but the admin login doesn't work. Also, every time I run
manage.py syncdb
The script keeps informing me that I just install the auth system and don't have any users yet. Then it prompts me to create a super user.
Because nothing is persisting, I can't login to the admin page and any data I attempt to save using the built in shell doesn't keep either.
is it possible that you fire up a new issue at the issue tracker https://github.com/django-nonrel/djangoappengine/issues or at the mailing list http://groups.google.com/group/django-non-relational ? I think there might be a bug somewhere.
Depending on what you upgraded from, it's possible that you previously had no 'default partition' value - earlier versions didn't set one by default, but recent ones use 'dev:'. Try giving a --default_partition argument to manage.py.
I didn't end up changing anything but after trying it again on my Win 7 machine the next day, the issue wasn't there so it unfortunately isn't reproducible right now. Maybe logging out and logging back in changed some type of state after the install, that's my best guess. Sorry that I don't have any further information.

Categories