w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to redirect user to 404 page not found error when non admin try to access wp-admin or wp-login.php
I assume that you're trying to protect yourself from brute-force attacks? Why not just limit the frequency of allowed login attempts? There is a pretty solid plugin called "Limit Login Attempts" which will track per IP and the use of cookies. Check it out here: http://wordpress.org/plugins/limit-login-attempts/ Trying to mask the login page is an interesting idea, though. You could just create your own login page somewhere and have it interact with a custom login script that you write. This would allow you 301 redirect the login pages to a 404 page without messing with any core functionality. You could have a form at something like https://yourwpsite.com/supersecretlogin and then have it POST to a custom handler that uses the wp_signon method. Here's an example of how to log someone in

Categories : Wordpress

Django custom field gives an error when editing in admin
Well, I've figured that out. The problem is inside the very Django core. Fields just can't return Python objects containing some models.Field attributes like prepare_database_save, otherwise an error occures. My hack to solve that was to return tuple (MyClassObject, ) instead of just MyClassObject in to_python(). Odd, but what can I do... Maybe I'll try to post an issue somewhere on Django's Github page.

Categories : Django

Django error while template rendering: NoReverseMatch found
As FoxMaSk has commented you should replace: {{ protocol }}://{{ domain }}/accounts/password/reset/confirm/{{uid}}/{{token}} with: {{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uid36=uid token=token %} Note the single quotes around the view name in the url, this is required in Django 1.5+ (not sure what version you are using). More importantly I believe the error lies here: message = t.render(Context({"domain":"foo.com","protocol":"https"})) You are not passing your uid or token into the context when rendering the template which is why you are seeing empty values in the traceback message for these variables: NoReverseMatch: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': '', u'token': ''}'

Categories : Python

Raise django admin validation error from a custom view
Not sure I understood what you want well: You have a view, by definition a public page. You want it to display an error message in the admin pages (by definition privates page) ? It's odd. But if you want so. To display an error in the admin pages, use the Django Message Framework. It's what is in use to display the yellow rows with errors/notifications on the top of the pages. from django.contrib import messages messages.error(request, "Something goes wrong sending transaction mail"); Indeed, validation errors an only displayed with forms. And thus, they are to be raised only in the clean() method of a form, a formset, or a field.

Categories : Django

Django unique, null and blank CharField giving 'already exists' error on Admin page
Since you have null=True, blank=True and unique=True, django is considering None or blank as a unique entry. Remove the unique constraint and handle the uniqueness part in the code.

Categories : Python

django search page not found error
Try changing the order of the URL matches. urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), (r'^tinymce/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': 'C:/Users/Kakar/web/cms/static/js/tinymce/' }), (r'^search/$', 'search.views.search'), (r'', include('django.contrib.flatpages.urls')), ) Just like in the documentation Also, for some reason, you are missing the ? in the query parameters. One more issue: You have a typo. You are sending resuts in the context, and doing {{results}} in the HTML

Categories : Django

Custom error page to handle Axis2Fault , EPR not found
I was able to solve this issue by changes in axis2.xml file as below : "sendStacktraceDetailsWithFaults" parameter to > false "DrillDownToRootCauseForFaultReason" parameter to > false Previously these two parameters were true, due to which whole of the stack trace was getting displayed. Hope this helps for some one with same issue. I couldn't find much in the internet.

Categories : Java

Custom 404 error page in Sitecore don't appears when file (.pdf and other) not found
I think this will help you. <system.web> <customErrors defaultRedirect="Error.aspx" mode="On"> <error statusCode="500" redirect="Error.aspx"/> </customErrors> </system.web> U can add additional tags and mention available error codes and the page where you want to redirect.

Categories : Asp Net

django admin url not found and missing path
To commet this line in urls resolve my problem: #url(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), So I must think about to handle my dynamic image load config. But this is a other point. Thanks!

Categories : Django

Using Django admin template tags
The template tags from the Django admin are not really re-usable. To use the search_form tag, you would have to provide a ChangeList instance, which is very tightly coupled to the Django admin. If you were able to reuse the tag, you would have to load the tag library first. The search_form tag is in django.contrib.admin.templatetags.admin_list. Therefore, you would have to load the admin_list tags before could use it. {% load admin_list %} {% search_form cl %}

Categories : Django

How to use the Django admin template for a form?
I think its better to override the admin interface. https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

Categories : Python

How can I order the native django users in the django admin page based on creation time?
Shouldn't it just be: ordering = ['-date_joined'] You can order by any field the model gives you. Since you didn't specify the UserModel you are using, I guess you are talking about the BaseUser? If so, you can order by: first_name last_name id email date_joined username [is_staff] # bool [is_active] # bool

Categories : Python

Django admin template refuses to be overridden on ubuntu?
Alasdair pointed me to the problem. I assumed os.path.abspath(os.path.dirname(__name__)) would always point to the absolute directory one level up from the settings.py file. Unfortunately, this is not the case and I'm still not sure how this magic code is supposed to work. It seems to have something to do with the directory from which you start the python interpreter. In my case, I was starting gunicorn from /project_base/project_name (the directory containing settings.py). Starting gunicorn from /project_base fixed the problem.

Categories : Django

How do I correctly extend the django admin/base.html template?
Indeed, your problem is an infinite recursion loop as base.html extends itself. To achieve what you want you should override admin/base_site.html instead (which in turn extends base.html). That way you can replace only the blocks you're interested in.

Categories : Django

How to reverse a custom admin url in Django 1.5?
Try changing name of the view to include application and model names: ... my_urls = patterns('', url(r'^settings/([A-Za-z0-9]*)', self.admin_site.admin_view(self.settings), name="common_variable_settings")) ... The admin_urlname template filter returns "full" names, see it's source code: @register.filter def admin_urlname(value, arg): return 'admin:%s_%s_%s' % (value.app_label, value.module_name, arg) So definitely You need to name Your view "appname_modulename_settings". Maybe then try changing regular expression to something like this: r'^settings/([A-Za-z0-9]+/)?$'

Categories : Python

Cant get Custom widget to work by replacing django's default date time widget in django admin
For a jQuery widget you'll need to include the jQuery.js (or whatever name you have) core library file in your html header. The TypeError: $ is undefined ... makes it seem as if you might have forgotten to do that. The TimeZoneDate widget is claiming the widget is called id="date_time_tz" but the js is attempting to work with something called $('#date-time-tz') I'd suggest changing one or the other so that they match! Maybe in the widget; id="date-time-tz"

Categories : Python

Django: Reverse not found > {% url %} in template
The problem is that "United Kingdom" doesn't match the regex [-w]+. If you also want to match spaces, you should change your regex to [-w ]+. Example: url(r'^(?P<country>[-w ]+)/$', CountryListView.as_view(), name='list_by_country') You can also choose to match s instead of just a single space character.

Categories : Django

How do I add a custom button next to a field in Django admin?
In my case I am making an API call with a button I create so I'll throw in how I did that too. Ofcourse your button can do whatever you like. First, in your model create a function that will output your button. I will use my example, i.e. models.py: class YourModel(models.Model): .... def admin_unit_details(self): # Button for admin to get to API return format_html(u'<a href="#" onclick="return false;" class="button" ' u'id="id_admin_unit_selected">Unit Details</a>') admin_unit_details.allow_tags = True admin_unit_details.short_description = "Unit Details" I then added the field as readonly and added it to the fieldsets, note you can only have either fields or fieldsets defined on the model admin. I aslo added media to

Categories : Django

Django Admin custom list_display name and ordering
Figured it out; I named the reference tot he _class Model wrong; Ordering should be: ordering = ('level', '_class__name') Order field should be: class_.admin_order_field = '_class__name'

Categories : Django

Django admin sortable custom fields
You don't. The admin screen relies on QuerySet.order_by(); it can only do the ordering that can be represented in an ORDER BY clause. Relevant source: https://github.com/django/django/blob/a89c856a7aadc830951342a1fa49c1a1b5ac9156/django/contrib/admin/views/main.py#L387 Consider what would happen with large datasets - in order to have the pagination be consistent, the admin would have to evaluate your normalization function for every row in the database, for every request.

Categories : Django

Custom User Model in admin on Django 1.5
As you say, the UserCreationForm references auth.User directly. The Django docs on custom users and built in auth forms state that you must rewrite it for any custom user model. UserCreationForm Depends on the User model. Must be re-written for any custom user model. There is a related ticket Ticket 20086, which was initially closed as invalid, because the user creation form is working as documented. There is a full example on the same page, which shows you how to rewrite the forms and register a custom user model in the admin.

Categories : Python

Django override base_site.html for a custom admin
You can use change_form_template or change_list_template template as per your need. Example : class xxxxAdmin(admin.ModelAdmin): change_form_template ='admin/cutomize_form.html' Regards, Ansh J

Categories : Django

Custom Filter in Django Admin returns SuspiciousOperation
This appears to be a bug in Django, when you have double-underscores for the filter path (first element of the tuple)... in your case 'model1__model2__property' NOTE: now fixed in Django 1.7 More details here: https://code.djangoproject.com/ticket/19182 It's quite ugly but so far the only workaround I found was to paste this fixed and overridden method into the ModelAdmin where you want to use that list_filter: def lookup_allowed(self, lookup, value): """ Copy and pasted from ModelAdmin to fix bug in Django https://code.djangoproject.com/ticket/19182 """ from django.db.models.constants import LOOKUP_SEP from django.db.models.sql.constants import QUERY_TERMS from django.contrib.admin import FieldListFilter from django.contrib.admin import widgets mod

Categories : Django

django-admin.py can't find custom settings file
What I recommend doing: Create a normal settings.py file and import one of the others in there. This avoids duplication of settings shared among the three scenarios + it is actually the recommended way of doing it according to the DRY principle. Typically, you will only have the set the debug parameter, database settings and private keys in the specific settings files. All the other settings should be shared among all scenarios to avoid forgetting to update one and getting hard to debug errors.

Categories : Django

Wordpress adding a news page with custom template loads wrong template
Create a php file inside your theme folder with the name 'page-news.php'. Copy the same code as your 'page.php' file inside page-news.php. This is the file that will be loaded when you enter http://www.website.be/news. Customize this file as you wish.

Categories : PHP

How can I redirect where the Django admin page takes you when you log in?
Django's admin site login works without redirects. Admin site just hooks on every request started with "/admin/", and if the user is not authorized - shows login form on the same url. I.e. if you want to give access to the admin itself - just point users on "/admin/", without "login/". If you want to use login form for your project - write an appropriate view or use one provided by Django.

Categories : Django

502 Bad Gateway on a single django admin page
Find one error in your nginx config file proxy_read_timeout 360; should read uwsgi_read_timeout 360; HttpUwsgiModule module has its own timeout directives. http://wiki.nginx.org/HttpUwsgiModule#uwsgi_read_timeout

Categories : Django

django admin page dropdown foreign key
The Dropdown control is the default one for ForeignKey. Default admin configuration should work : from labels.models import Label from audiobooks.models import Audiobook from django.contrib import admin admin.site.register(Label) admin.site.register(Audiobook)

Categories : Django

Filter data in django admin page
Django does not do this out of the box. One third-party package I often see recommended to accomplish this common task (as opposed to writing your own ajax to do it) is django smart selects.

Categories : Django

django admin - add custom form fields that are not part of the model
It it possible to do in the admin, but there is not a very straightforward way to it. Also, I would like to advice to keep most business logic in your models, so you won't be dependent on the Django Admin. Maybe it would be easier (and maybe even better) if you have the two seperate fields on your model. Then add a method on your model that combines them. For example: class MyModel(models.model): field1 = models.CharField(max_length=10) field2 = models.CharField(max_length=10) def combined_fields(self): return '{} {}'.format(self.field1, self.field2) Then in the admin you can add the combined_fields() as a readonly field: class MyModelAdmin(models.ModelAdmin): list_display = ('field1', 'field2', 'combined_fields') readonly_fields = ('combined_fields',)

Categories : Django

How to create a custom date time widget for the django admin?
I think you can create a more generic widget. First, separate your js, html and media for create a unique widget. widgets.py class DatTimeField(forms.Textarea): def render(self, name, attrs = None): final_attrs = self.build_attrs(attrs,name=name) return "Here you have to return the html of your widget, for example: mark_safe(u'<input type=text %s value=%s class='your_css_class'/>' % (flatatt(final_attrs), value))" Now in your admin class, try this: class YourClassAdmin(admin.ModelAdmin): class Media: css = { "all": ("my_styles.css",) } js = ("my_code.js",) formfield_overrides = { models.DateTimeField : {'widget': DatTimeField()}, } If you want to customize your widgets, I suggest you to see the

Categories : Python

Django custom forms for Admin deleting fields dynamically
Definitely your best bet is ModelAdmin. I think you got it right except for the if test. You should be able to do it like this: class GiftAdmin(admin.ModelAdmin): model = Gift def get_form(self, request, obj=None, **kwargs): self.exclude = [] # self.instance.pk should be None if the object hasn't yet been persisted if obj is None: self.exclude.append('giftbought') return super(GiftAdmin, self).get_form(request, obj, **kwargs) admin.site.register(Gift, GiftAdmin) Notice there are minor changes to the method code. You should check the docs, I'm sure you'll find everything you need there. Hope this helps!

Categories : Django

Django Admin: Change URL links in change_list page
You can edit the admin URL by extending the admin model. Like this. class MyModelAdmin(admin.ModelAdmin): def get_urls(self): urls = super(MyModelAdmin, self).get_urls() my_urls = patterns('', (r'^my_view/$', self.my_view) ) return my_urls + urls def my_view(self, request): # custom view which should return an HttpResponse pass You can here the full documentation here.

Categories : Django

django admin additional field on changelist page
Well, I found it out myself. The way to do it is to override the queryset() in BookAdmin class. Like: def queryset(self, request): return Book.objects.all().select_related('author') That is it. Django will load the Author in the same time it loads Book. So there will be only on database hit rather than over 100 hits.

Categories : Django

my django admin page don't have the css when viewed over the apache server
Tell Django where to find the static files (if you have not already). First, make sure you have STATIC_ROOT and STATIC_URL set correctly in `settings.py', and then on your live server simply run the following command. python manage.py collectstatic This will collect all static files necessary for the admin to render correctly. When running the development server (runserver) static files are automatically found using STATICFILES_FINDERS, but in production this is not the case, in-fact STATICFILES_FINDERS does somethine else in production, it finds and collects the files after `running python manage.py collectstatic ' they are then served in your case by Apache.

Categories : HTML

Django custom user model in admin, relation "auth_user" does not exist
After some digging around I found this https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms The culprit is a function clean_username inside UserCreationForm inside django.contrib.auth.forms.py. A few tickets have been created, but apparently the maintainers don't think it's a defect: https://code.djangoproject.com/ticket/20188 https://code.djangoproject.com/ticket/20086 def clean_username(self): # Since User.username is unique, this check is redundant, # but it sets a nicer error message than the ORM. See #13147. username = self.cleaned_data["username"] try: User._default_manager.get(username=username) except User.DoesNotExist: return username raise forms.Valida

Categories : Django

how to override delete confirmation page in django admin site?
To override an external app view, just override the url. See How to override a view from an external Django app.

Categories : Python

How can I add a button into django admin change list view page
First add the button. Django admin comes with jQuery so let's use it. Make a static file path/to/adminfix.js: (function($) { $(document).ready(function($) { $(".object-tools").append('<li><a href="/path/to/whatever/" class="addlink">Custom button</a></li>'); }); })(django.jQuery); In admin.py in your ModelAdmin: class Media: js = ('path/to/adminfix.js', ) Now create a custom view at "/path/to/whatever/". This can be a regular view (just like other pages on your website) or a custom admin view in Admin.py. The get_urls method on a ModelAdmin returns the URLs to be used for that ModelAdmin in the same way as a URLconf. Therefore you can extend them as documented in URL dispatcher: class MyModelAdmin(admin.ModelAdmin): def get_urls(self):

Categories : Django

The New line ( ) wasn't selected in Django admin changelist page
New lines are ignored by browsers in HTML. If you want to show them in different lines I think you should join them with <br> instead of and use allow_tags. class ArticleAdmin(admin.ModelAdmin): list_filter = ["category",] list_display = ('category','article_type', 'get_domains') filter_horizontal = ("domain",) def get_domains(self, obj): x ="<br>".join([str(s.name) for s in obj.domain.all()]) print x # printing fine return x get_domains.allow_tags = True Hope this helps!

Categories : Python

Creating a custom page for admin to add products
use below function in controller to add new product public function addNewProduct(Varien_Object $object){ $product = Mage::getModel('catalog/product'); $product->setSku('pro12'); $product->setAttributeSetId(9); $product->setTypeId('simple'); $product->setName('Product title'); $product->setCategoryIds(array(7)); $product->setWebsiteIDs(array(1)); $product->setDescription('Product Full description'); $product->setShortDescription('Product Short description'); $product->setPrice(250.00); $product->setWeight(30.00); $product->setVisibility(4); $product->setStatus(1); $product->setTaxClassId(0); $product->setStockData(array(

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.