If I try to add blog.apps.BlogConfig string to INSTALLED_APPS (to define the blog app), local server won't start giving me an error. Photos attached below:
I am expecting for the separate section to appear on site.
Was doing it by tutorial of the Youtuber Corey Schafer:
https://www.youtube.com/watch?v=qDwdMDQ8oX4&list=PL-osiE80TeTtoQCKZ03T
It's so simple.
Just put your application name in INSTALLED_APPS list.
Like, if you have application name "blog", then just put ...
INSTALLED_APPS = [
'blog',
...
]
That's it !
Still, if you need to put name of your application in INSTALLED_APPS list as "blog.apps.BlogConfig", then just go to apps.py in your application, and put ...
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'
Thanks !
Recently I started my web project using Django with reference to some youtube tutorials. I have created a project named admin and created an app named user. From many tutorials they have created separate urls.py for both project and app. But in my case only the project's urls.py is working.
For example, I have defined the index view (my home page) in project's urls.py and login view in app's urls.py. When I try to access the login as it shows:
The current path, login, didn't match any of these
Can anyone help me to find out the solution for this?
Django only checks the URLs of the project's ROOT_URLCONF e.g. urls.py. If you want to include the URLs of a certain app, you can do the following:
In your projects urls.py:
from django.urls import include, path
urlpatterns = [
path('user/', include('user.urls')),
# others...
]
Then, if you go to url yoursite.com/user/, it will find the URLs specified in the app's urls.py. For more information see the docs.
Also make sure that your app user is in the INSTALLED_APPS of your settings.py, like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
'user',
...
]
So that django knows about your app.
So I've been following django tutorial and things worked well, but then I decided to try and write my own apps following the tutorial. I created a view, and updated the /pysent/settings.py file with this section
INSTALLED_APPS = [
'pressent.apps.PressentConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
However, when I save the file, I get an error from the running server:
ImportError: No module named PressentConfig
If I change the first line above to only
`pressent`
I get no error message. On the other hand, with the tutorial example, things work with the line
polls.apps.PollsConfig
django version is supposed to be 1.9.6
>>> import django
>>> django.VERSION
(1, 9, 6, 'final', 0)
>>>
What is going on here?
Edit
The solution was to edit pysent/pressent/apps and add
class PressentConfig(AppConfig):
name = 'pressent'
The reason to the problem was I changed the folder name.
I'm going to presume pressent is your django application name (project name I think is pysent), so there's a directory named pressent and inside it has a apps.py file, and finally that file has a class named PressentConfig.
PressentConfig class example:
from django.apps import AppConfig
class PressentConfig(AppConfig):
name = 'pressent'
# Exec some configs for this app. Maybe overriding the ready method
Look into your app directory, and check if there's a module named app and in that module a class named PressentConfig. If there isn't, then the app config approach will not work unless you create a configuration for your app. Read more Django: configuring apps
I'm building a Django app and now I'm in production. I have this problem: after performing manage.py syncdb (all it's ok) I go into admin and I can not find the models tables . My admin.py file is present and this is my file url.py:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'stambol.views.home', name='home'),
# url(r'^stambol/', include('stambol.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Where is the problem?
Permissions
First off, make sure you have permission to edit the missing models. It's common to be developing with a superuser account, and then to test your production deployment with a different non-superuser account. If you don't have at least read permission, the class won't be listed at all in the admin.
I think this is the most likely cause, but I will leave the rest since I had already written it.
Discovering your admin registrations:
One notable difference between runserver and a production server is that when you run runserver, it imports all your models.py files and validates the models. This does not happen in production, so if you register your models with the admin inside models.py you need to be sure to import that file so that code runs. You could do so in your main url conf.
The preferable solution is to do your registration in per-app admin.py files so they are picked up by autodiscover.
Settings:
You do need admin listed in installed apps, as #Pratik says. It also has some dependencies, as mentioned here. Installed apps should contain at least this:
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions'
'django.contrib.messages',
'django.contrib.admin',
#...
'myapp',
#...
]
Make sure the dir containing your app myapp is in your python path, so that myapp is picked up by autodiscover. This is working correctly for you already, or else you would get something like ImportError: No module named myapp.
Restarting the server:
Finally, just to recap what is buried deep within comments, you can restart your production server after making any code changes by touching your wsgi file: touch wsgi.py. Use tab-completion when you do this to be sure you're touching the existing wsgi file and not creating a new one thanks to a typo or some such. The wsgi file you're touching should contain something like this:
...
# tell django to find settings at APPS_DIR/mainsite/settings.py'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mainsite.settings'
# hand off to the wsgi application
application = WSGIHandler()
Still broken?
If things still aren't working as expected, think farther outside the box. Keeping in mind that you're new to your production environment, is it possible some other code besides your own is being served up? Make some obvious change to a front-end page, restart the server, and see if it works. This is just a shot in the dark, of course.
from django import admin
from example.models import YourModel
admin.site.register(YourModel)
# or
class ModelAdmin(admin.ModelAdmin):
pass
admin.site.register(YourModel, YourModelAdmin)
This should do the trick
Make sure you have the below removed as comments inside INSTALLED_APPS in settings.py. Then run ./manage.py syncdb again. They should like as shown below without the # in front of them
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
I've read all the other threads but I still don't get why my apps are not showing up in Django admin. Everything else works fine.
My apps are in settings.py
I have admin.autodiscover in my root urls.py file
from django.conf.urls.defaults import *
from django.conf import settings
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', direct_to_template, {
"template": "homepage.html",
}, name="home"),
url(r'^admin/invite_user/$', 'signup_codes.views.admin_invite_user', name="admin_invite_user"),
url(r'^account/signup/$', "signup_codes.views.signup", name="acct_signup"),
(r'^account/', include('account.urls')),
(r'^profiles/', include('basic_profiles.urls')),
(r'^notices/', include('notification.urls')),
(r'^announcements/', include('announcements.urls')),
(r'^tagging_utils/', include('tagging_utils.urls')),
(r'^attachments/', include('attachments.urls')),
(r'^comments/', include('threadedcomments.urls')),
#
(r'^wayfinder/', include('wayfinder.urls')),
(r'^site/', include('jsite.urls')),
(r'^kiosk/', include('kiosk.urls')),
(r'^navigator/', include('navigator.urls')),
(r'^location/', include('location.urls')),
(r'^event/', include('event.urls')),
#(r'^news_reader/', include('news_reader.urls')),
#(r'^weather_reader/', include('weather_reader.urls')),
(r'^admin/(.*)', admin.site.root),
)
if settings.SERVE_MEDIA:
urlpatterns += patterns('',
(r'^site_media/', include('staticfiles.urls')),
)
All my apps have an admin.py file containing something like
from django.contrib import admin
from event.models import Event
class EventAdmin(admin.ModelAdmin):
list_display = (
'short_name',
'long_name',
'locations',
'categories',
'description',
'phone',
'email',
'url_source',
'url_location',
'external_ref',
'show_event'
)
admin.site.register(Event, EventAdmin)
And I have restarted the server over and over ;-)
I am building on top of Pinax, but from my reading, it shouldn't change anything. Any clue what might be wrong ?
Do you have your apps in the INSTALLED_APPS section in settings.py?
Make sure it has your apps listed there. My section reads
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'squick.items',
'cowsite.search',
'cowsite.posts',
)
for instance. I'm pretty sure for security, they won't show up in the admin unless they are in installed apps. I think I had this same issue, where I couldn't get cowsite to show up in the admin.
The Django docs say about the admin page: "By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order"
By coincidence I had the same problem this morning. Briefly, this is what worked for me (see references for details):
In the top level directory of MyApp (ie same directory as models.py, etc.) I added a python module admin.py, containing:
from models import ThisModel, ThatModel
from django.contrib import admin
admin.site.register(ThisModel)
admin.site.register(ThatModel)
Then in mysite directory I did syncdb and runserver, and ThisModel and ThatModel were in the admin interface.
Does that work for you?
Best wishes
Ivan
** References
(I am a new member so I am allowed to post one hyperlink only!)
Django tutorial: Make the poll app modifiable in the admin
There was also a query on the Pinax google group recently titled, "How to add my app to Admin in a Pinax project?"
Are you logging in to admin as a superuser? If not, it could be a permissions problem.
Not sure which version of django you're using but the current docs suggest including the admin urls.
('^admin/', include(admin.site.urls))
For other's coming across this, I had the same issue due to grappelli.dashboard being in the installed apps but not actually installed in the virtualenv, so do a pip freeze and ensure all your requirements are actually installed.
add your app name in "settings.py" file installed app.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
]
If the other solutions did not work for you, try to load your admin dashboard in a different browser. One of my apps was not displaying on the admin dashboard while I was using Google Chrome. After trying multiple answers others suggested, I decided to use Firefox instead. Voila! I was finally able to see my app on the admin dashboard.
You didn't answer Antony's question. Are you logging in as a superuser, or at least with a user with add/edit rights for the applications? If not, you won't see them.
I had the same problem, what worked for me was changing this line in urls.py:
url(r'^admin/', include(admin.site.urls)),
to
url('^admin/', include(admin.site.urls)),
(Removing the r in the first bit of code)
For some reason I am not aware of, the Polls became visible in admin after that.