why class-based view returned type object 'Profile' has no attribute 'model'?

i have a website with django.this is the project urls.py:urlpatterns = [url(r'^admin/', admin.site.urls),url(r'^', include('accounts.urls')),url(r'^login/$', LoginView.as_view(), name='login'),url(r'^register/$', RegisterView.as_view(), name='register'),url(r'^logout/$', logout_view, name="logout")]and this is the accounts.urls:from . import viewsurlpatterns = [url(r'(?P<username>[\w]+)/$', views.Profile.as_view(), name='profile_cbv'),]and this is Profile model:class Profile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='profile'...

How to exclude instances from Admin site in Django

In Django, I have created another separate Admin site. This is what my SiteUserAdmin class looks like:class SiteUserAdmin(UserAdmin):form = UserChangeFormadd_form = UserCreationFormlist_display = ('username' ,'email',)fieldsets = ( (None,{'fields':('username','email','password')}),('Permissions',{'fields':('is_active','is_admin_user','groups')}))Among all the users, there are superusers whose "is_superuser = True". Is there anyway to hide such superusers from the list of editable users of the admin site?In another word, I am not excluding other fields from the Admin site...

Django: one url search in two models (cbv)

Using Django, I'm looking for a way to use one url patern (with slug) to query one model and if nothing is found query a second model. I'm using Class Based Views.I am following this answer, and the next View is being called. But then I get the following error:"Generic detail view must be called with either an object pk or a slug."I can't figure out how to pass the slug to the next View.My url:url(r'^(?P<slug>[-\w]+)/$', SingleView.as_view(), name='singleview'),My CBV's:class SingleView(DetailView): def dispatch(self, request, *args, **kwargs): post_or_page_slug...

Django-admin createsuperuser does not work

The Django documentation says syncdb is deprecated and replaced by migrate. But for a fresh install of Django 1.8, if I run python manage.py migrate and then django-admin createsuperuser, I get an error of:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.But if I run python manage.py syncdb, it gives me a warning about deprecation BUT at the same time prompts me to create a super user, w...

Using Multiple URL Parameters to get_object in Class-Based-View

Alright, I'm fairly new to this, I've been working on my Project for a couple months now and I'd like to create URLs that accept multiple parameters to call a View. A sample URL would look like this:http://www.sample.com/builders//m//I've got this implemented successfully, by overriding get_object in my DetailView, but I'm wondering if there is a better/easier method for accomplishing this or if this is considered a bad practice. Any guidance would be appreciated.urls.pyurlpatterns = [ # url(r'^$', builder_list, name='list'), # url(r'^create/$', builder_create, name='...

Django GET ?q="parameter" in get_queryset Class Based View

How do I access the "parameter" word in the url:operations_product_search/?q=parameterhere:class ASearchView(ListView):...def get_queryset(self, **kwargs): q = self.kwargs["q"] <--- This is not working It should be self.request.GET['q']. [XXX]I get query parameters using query_paramsdef get_queryset(self): q = self.request.query_params.get('q', None) [XXX]

Using Amazon EC2: IP address working fine, but public DNS not

I just finished setting up my app on Amazon EC2 using Nginx and gunicorn When I type in amazon's IP address: 54.218.54.156, the app shows up fine and dandy, but when I use the public DNS: ec2-54-218-54-156.us-west-2.compute.amazonaws.com I get the following message from Nginx...My sites-available file looks like this...server { listen 80; server_name 54.218.54.156; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/ubuntu/flowershop; } location / { include proxy_params; proxy_pass http://unix:/hom...

No module named 'social_django' when creating superuser

I'm running a django project and I get this error when I try to add a superuser with the commandpython manage.py createsuperuserthe error I get is >File "manage.py", line 15, in <module> execute_from_command_line(sys.argv)>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute()>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute django.setup()>File "/home/boidot/anaconda3/lib/python3.6/site-p...

Django URL conf error

I have the following message when I try to use reverse or reverse_lazy: The included URLconf 'ph.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular importWhen I use the urls (without using reverse or reverse lazy) is working with no issue. I tried different combination of urls the same resultsWhat I'm doing wrong ?ph is the project. In the project I include the urls for the application:from django.conf import settingsfrom django.conf.urls import url, includefrom django.contrib import adm...

Reusing the same URL pattern in Django

I'm building a simple web store. There are Category objects and Product objects.I want the URLs for both to be at the top level, ie a Category named "Jacket" would be at http://example.com/jacket and a Product named "Foo" would be at http://example.com/foo.I'm not sure how to handle this in my URLs since both match the same regular expression. I can just have a single DetailView which overwrites get_object(), first checking for a product with the slug and then checking for a category with the slug and returning whichever it finds first. (In the event of both a product and c...

Why does "heroku run python manage.py send_queued_mail" work from command line but not when in a clock.py file for Heroku?

My clock.py below. I can use heroku run python manage.py send_queued_mail all day long but including run python manage.py send_queued_mail in a clock.py file causes a syntax error.clock.py:from apscheduler.scheduler import Schedulersched = Scheduler()@sched.interval_schedule(minutes=1)def timed_job(): python manage.py send_queued_mailsched.start()while True: passHeroku error message (from log):2014-01-24T01:31:47.256648+00:00 app[clock.1]: File "clock.py", line 72014-01-24T01:31:47.256648+00:00 app[clock.1]: run python manage.py send_queued_mail2014-01-24T01:31:...

What is a NoReverseMatch error, and how do I fix it?

I have some code and when it executes, it throws a NoReverseMatch, saying: NoReverseMatch at /my_url/ Reverse for 'my_url_name' with arguments '()' and keyword arguments '{}' not found. n pattern(s) tried: []What does this mean, and what can I do about it? The NoReverseMatch error is saying that Django cannot find a matching url pattern for the url you've provided in any of your installed app's urls. The NoReverseMatch exception is raised by django.core.urlresolvers when a matching URL in your URLconf cannot be identified based on the parameters supplied.To start debug...

NoReverseMatch at /category/clothes/ Django class based views

I have a django project that is close to an e-commerce wesite in terms of functionality. There are four pages linked to one another. First page displays Categories, 2nd Subcategories, 3rd Product list and 4th Product detail and I'm using slugs to navigate.ERRORReverse for 'product-list' with arguments '('', 'women-clothes')' and keyword arguments '{}' not found. 1 pattern(s) tried: ['category/(?P<category_slug>[-\\w]+)/(?P<subcategory_slug>[-\\w]+)/$']Category to Subcategory linking code on the category_list.html is <a href="{% url 'products-app:sub-category'...

route53 naked domain not reaching amazon elastic load balancer

I`m currently using route53 for 2 domains that points to the same website. Lets assume they are www.example.com and www.example.com.xx, I`ve created 2 hosted zones and maintained the configuration created by default. So, initially I had entries for NS an SOA in each hosted zone.My EC2 instances are behind Elastic Load Balancer, so my first step was to create aliases for both domains and it naked domains, having the following scenario: www.example.com name                   &n...

Django: same method different url

My url looks like:/api/v1/files//api/v1/files/100Is it a good practice to use the same function to match them? just like the following:class FileView(APIView): parser_classes = (MultiPartParser,) permission_classes = (IsAuthenticated,) @method_decorator(csrf_exempt) def dispatch(self, request, *args, **kwargs): return super(FileView, self).dispatch(request, *args, **kwargs) def post(self, request, pk = None): if pk is not None: Do something else: do somethingHow to use different functions in Class-based views?Thanks ...

Django Path to static files changing depending on the page

I have an index page with a list of mouvements in a datatable, each row has buttons that allow the user to press "Edit" to go to a new page where he can view the details of the mouvement.On index page and on the basic details mouvement page everything work fine, static files are loaded with the path /gestion_mouvements/static/...But when i use "(?P[0-9]+)/$" in my page url to be able to get the mouvement ID in the url, the loaded page change static path to gestion_mouvements/mouvementDetails/static/... for example and fail to load the static files since the path should be g...

Page 1 of 156  |  Show More Pages:  Top Prev Next Last