SiteProfileNotAvailable error - python

I know same question being asked many times. I have successfully setup all things. I didn't get this error when i run this on localhost. But when i run the site on deployment server i got this error not always but very often. When i refresh page 3 or 4 times the error disappears but keeps on coming again and again which is very annoying.
My directory structure related to problem is as:
project (folder)
profiles (folder)
models.py (file)
settings.py (file)
I have folder profilesin which there is models.py and i have class Profile there.
In settings.py i have included profiles folder to my apps also and i have set AUTH_PROFILE_MODULE = 'profiles.Profile'.
Also in Profile class i have added the path for application:
class Profile(UserenaLanguageBaseProfile):
class Meta:
app_label = 'profiles'
Can any one help me to figure out this issue??

AUTH_PROFILE_MODULE should be a string:
AUTH_PROFILE_MODULE = 'profiles.Profile'

I was using Django 1.4 trunck version, after upgrading the package again that problem is fixed.

Related

Django test command fail after changing models.py to a directory structure

This is in Django 2.0 , python 3.6.5
I have an app called posts, and I changed models.py to a folder structure, i.e., create a directory models and move the file models.py insid. Also config __ init__.py file, as explained next.
The project runs ok, but my test suite fails.
In my settings, installed apps i have the app as:
'myproject.apps.posts.apps.PostsConfig'
My app config (posts/apps.py)
from django.apps import AppConfig
class PostsConfig(AppConfig):
name = 'posts'
verbose_name = 'posts'
I have move posts/models.py to a directory structure. So I have
posts/models/models.py
posts/models/proxymodels.py
posts/models/__init__.py
inside models/__ init__.py I do import my models as explained in doc
from .models import Job
from .proxys import ActiveJob
The project works well, but when trying to run tests:
python manage.py test
I have this error:
RuntimeError: Model class tektank.apps.posts.models.models.Job doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
The model is a normal one, with fields, nothing extrange. The thing is that if I declare in the meta
class Meta:
app_label = 'posts'
I got the following error:
RuntimeError: Conflicting 'job' models in application 'posts': <class 'posts.models.models.Job'> and <class 'tektank.apps.posts.models.models.Job'>.
Note: If I use pytest, I run the command:
pytest
It runs OK
UPDATE
Same error if I execute:
./manage.py test myproject/apps/posts
If I execute only with app name, no tests are detected
./manage.py test posts
Ran 0 tests in 0.000s
OK
If I put the path of the tests folder, it works ok.
./manage.py test myproject/apps/posts/tests
Ran 2 tests in 0.074s
OK
./manage.py test posts.tests
Ran 2 tests in 0.103s
OK
But I am not satisfied with this, if I want to run all tests, it will still fail.

Django on Pycharm community edition seems to show false-positive error message

I'm new to Django and I'm using Pycharm Community 2018.1 to do my project.
While I was doing the first tutorial where you set up a model and corresponding admin page, Pycharm keeps showing this reference error which is perfectly fine when you look at the directory and the structure.
Is this what I get for using free Pycharm instead of paid Professional edition?
However, I know I'm a newb so I might be wrong here. Is it normal to get this error message in this situation?
I took a screenshot of error message(the left screen) and working Admin page(right screen) and here are my codes for models.py and admin.py
models.py (there is no problem with it)
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
# Create your models here.
#python_2_unicode_compatible
class Bookmark(models.Model):
title = models.CharField(max_length = 100, blank = True, null = True)
url = models.URLField('url', unique = True)
def __str__(self):
return self.title
admin.py (you can see unresolved reference error)
from django.contrib import admin
from bookmark.models import Bookmark
# Register your models here.
class BookmarkAdmin(admin.ModelAdmin):
list_display = ('title', 'url')
admin.site.register(Bookmark, BookmarkAdmin)
This warning can be solved by opening your actual project directory
Go to File->Open. Then choose your project directory, that is mysite and you are opened pyneer_django directory
It's nothing with the community edition

django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N

I am learning django from a book. According to instruction I created a forms.py file inside the same directory that views.py exists. Inside the file I wrote the following codes:
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required = False)
message = forms.CharField()
Then after entering virtual environment through env_mysite\scripts\activate I started python. After than I typed:
from mysite.forms import ContactForm
f = ContactForm()
But I receive the following message after a lot of file paths
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but
settings are not configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.
I opened setting.py file and USE_I18N was True
I have just followed the instruction from tutorial book I but don't understand what is wrong here. Could you please help
It seems like there's nothing wrong with that part of your project (the Form you've created there) or that language code configuration. It looks like you are simply not indicating which Django project to run, in your shell.
Please refer to this answer.
Command:
Run this command: python manage.py shell
Through this, you can access your models and form

django framework can't see new model online

I have to make some modification to a website built with the django framework (version 1.6).
The problem I am having is that I can not transfer the modification I made offline to the online server. I can see the new page, the database has been modified, but in the administration website the new category I created does not appear, thus i can not fill the fields with the new information.
The steps I went through are:
create the new model in models.py,
import the model in admin.py,
execute the command: touch wsgi.py
in order to reload the file.
In the offline version everything is working fine. I do not know that to do!
Code I added in admin.py file (I added the "Article" section):
from active.models import x, z, y, j, Article
class ArticleAdmin(admin.ModelAdmin):
ordering = ["title"]
list_display = ('title',)
search_fields = ['title']
admin.site.register(Article, ArticleAdmin)
Solved.
There was no problem at all, simply the user I access the administration site with did not have the right access to see the new section!
Have you imported admin in the admin.py file?
from django.contrib import admin

Django changing app name of Photologue

i have installed photologue - A customizable plug-in photo management application for the Django web framework here into my project without problem...
now i want to change app name in admin page which is photologue. for this i have used ugettext_lazy but i got an error when i define this to all Meta:
from django.utils.translation import ugettext_lazy as _
class Meta:
app_label = _('newappname')
Error:
ValueError at /admin/
Cannot create form field for 'effect' yet, because its related model
'PhotoEffect' has not been loaded yet
Is there any easy way for changing app name, i have looked a lot but didnt find...
Django does not support app renaming in the admin right now, but ticket #3591 was raised to add that functionality, so hopefully it will be added.
There are several ways of acomplishing that. The simplest and preferred would be changing the main admin template and using whatever name you want as the app name there.
Other solutions:
How to change the name of a Django app?
https://stackoverflow.com/a/6312798/342473
http://djangosnippets.org/snippets/1882/

Categories

Resources